Android 时间轴的实现

来源:互联网 发布:c语言打印图形函数 编辑:程序博客网 时间:2024/05/16 07:30


直接上代码


xml布局:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content">        <View            android:id="@+id/iew_1"            android:layout_width="1dp"            android:layout_height="0dp"            android:layout_marginLeft="41dp"            android:background="@color/light_gray" />        <RelativeLayout            android:id="@+id/rl_title"            android:layout_width="match_parent"            android:layout_height="wrap_content">                <ImageView                    android:layout_width="20dp"                    android:layout_height="20dp"                    android:layout_centerVertical="true"                    android:layout_marginLeft="32dp"                    android:background="@mipmap/yuan" />        </RelativeLayout>        <TextView            android:id="@+id/title"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_below="@id/iew_1"            android:paddingBottom="20dp"            android:layout_marginLeft="55dp"            android:lineSpacingMultiplier="1.5"            android:textColor="#A6A6A6" />        <View            android:id="@+id/v_line"            android:layout_width="1dp"            android:layout_height="wrap_content"            android:layout_below="@+id/rl_title"            android:layout_marginLeft="41dp"            android:background="@color/light_gray" /></RelativeLayout>
两个View实现的是与圆圈上下的两根竖线,
ImageView实现就是圆圈
activity代码:
package app.view.home.insertclass;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.RelativeLayout;import android.widget.TextView;import org.xutils.view.annotation.ContentView;import org.xutils.view.annotation.ViewInject;import org.xutils.x;import app.R;/** * Created by sch on 2016/9/27. */@ContentView(R.layout.insert_class_catalog_group_content)public class ICCGroupContentAdapter extends BaseAdapter {    Context context;    private LayoutInflater inflater;    @ViewInject(R.id.title)    private TextView textView;    @ViewInject(R.id.v_line)    private View line;    private View view;    private String[] title = {            "只手上飞机是克服了收款方sdfsafjaslfjlasdjlfjlsadjfladslfjldsajfldslfjldsfslafjlsjfpwelfmdslfjsflaslfjlasf式",            "只手上飞机是克服了收款方sadfkasfnl式只",            "回头啊,莫回头!曾经谁都曾回望自己的过去,但我从不曾想回头,是女孩也该向前进,找到更好的你自己,",            " FB上面有一个视频,名字叫做Alwayslikeagirl。视频里采访了不同年龄段的人,有小男孩,也有女青年",            "有一些姑娘,既能够画着淡妆,踩着小高跟,花枝招展,巧笑嫣然地出现在人前;也能够穿着旧T恤和短裤,连一口水都没时间喝却一句怨言都没有。"    };    public ICCGroupContentAdapter(Context context) {        this.context = context;    }    @Override    public int getCount() {        return title.length;    }    @Override    public Object getItem(int position) {        return null;    }    @Override    public long getItemId(int position) {        return 0;    }    @Override    public View getView(int position, View convertView, ViewGroup parent) {        inflater = LayoutInflater.from(parent.getContext());        View root = x.view().inject(this, inflater, parent);        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) line.getLayoutParams();        params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.rl_title);        params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.title);        line.setLayoutParams(params);        textView.setText(title[position]);        return root;    }}

代码解释:
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) line.getLayoutParams();        params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.rl_title);        params.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.title);        line.setLayoutParams(params);
这一部分代码是设置圆圈下面的竖线的高度,使其自适应高度

0 0
原创粉丝点击