1. 程式人生 > >快遞物流時間軸

快遞物流時間軸

效果圖
這裡寫圖片描述
Activity程式碼

            //倒序
            Collections.reverse(mList);
            CourierAdapter adapter = new CourierAdapter(this,mList);
            mListView.setAdapter(adapter);

Adapter程式碼

public class CourierAdapter extends BaseAdapter {

    private Context mContext;
    private List<CourierData> mList;
    //佈局載入器
private LayoutInflater inflater; private CourierData data; public CourierAdapter(Context mContext, List<CourierData> mList) { this.mContext = mContext; this.mList = mList; //獲取系統服務 inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override
public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder = null
; //第一次載入 if(convertView == null){ viewHolder = new ViewHolder(); convertView = inflater.inflate(R.layout.layout_courier_item,null); viewHolder.tv_remark = (TextView) convertView.findViewById(R.id.tv_remark); viewHolder.tv_zone = (TextView) convertView.findViewById(R.id.tv_zone); viewHolder.tv_datetime = (TextView) convertView.findViewById(R.id.tv_datetime); //設定快取 convertView.setTag(viewHolder); }else{ viewHolder = (ViewHolder) convertView.getTag(); } //設定資料 data = mList.get(position); viewHolder.tv_remark.setText(data.getRemark()); viewHolder.tv_zone.setText(data.getZone()); viewHolder.tv_datetime.setText(data.getDatetime()); return convertView; } class ViewHolder{ private TextView tv_remark; private TextView tv_zone; private TextView tv_datetime; } }

xml佈局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <View
            android:layout_width="2dp"
            android:layout_height="30dp"
            android:background="@color/colorPrimary"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/timeline_green"/>

        <View
            android:layout_width="2dp"
            android:layout_height="100dp"
            android:background="@color/colorPrimary"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:background="@drawable/timeline_content"
        android:orientation="vertical"
        android:padding="10dp">

        <TextView
            android:id="@+id/tv_remark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:text="你的快件已經到達北京"
            android:textColor="@color/colorPrimary"
            android:textSize="18sp"/>

        <TextView
            android:id="@+id/tv_zone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:paddingLeft="10dp"
            android:text="北京"
            android:textColor="@color/colorAccent"
            android:textSize="15sp"/>

        <TextView
            android:id="@+id/tv_datetime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:text="2016-11-12"/>

    </LinearLayout>

</LinearLayout>