Recyclerview实现时间轴物流详情效果

先放上效果图:

物流的小图标:

用的是Recyclerview,需要添加依赖,在项目的build.gradle文件里添加

 compile 'com.android.support:recyclerview-v7:25.4.0'

ExpressActivity

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.littlejie.app.R;

import java.util.ArrayList;
import java.util.List;

public class ExpressActivity extends AppCompatActivity {

    private RecyclerView express_recyview;
    List<ExpressBean.ResultBean.ListBean> expressBeanList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_express);
        
        initList();
        initView();
    }

    private void initList() {
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-20","17:55:00","投递并签收,签收人:单位收发章 *【毕节地区】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-18","17:34:00","离开纳雍县 发往纳雍县阳长邮政支局【毕节地区】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-18","09:59:00","到达  纳雍县 处理中心【毕节地区】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-18","07:40:00","离开贵阳市 发往毕节地区(经转)【贵阳市】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-17","07:53:00","到达贵阳市处理中心(经转)【贵阳市】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-16","12:04:00","离开长沙市 发往贵阳市(经转)【长沙市】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-15","21:46:45","郴州市邮政速递物流公司国际快件监管中心已收件(揽投员姓名:侯云,联系电话:)【郴州市】",""));
        expressBeanList.add(new ExpressBean.ResultBean.ListBean("2016-06-15","21:44:04","离开郴州市 发往长沙市【郴州市】",""));
    }

    private void initView() {
        express_recyview = (RecyclerView) findViewById(R.id.express_recyview);
        express_recyview.setLayoutManager(new LinearLayoutManager(ExpressActivity.this,LinearLayoutManager.VERTICAL,false));
        express_recyview.setAdapter(new ExpressRecyAdapter(this,expressBeanList));

    }
    
}

ExpressActivity对应的布局文件activity_express.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.littlejie.app.express.ExpressActivity">

    <RelativeLayout
        android:gravity="center_vertical"
        android:layout_width="match_parent"
        android:layout_height="48dp">

        <TextView
            android:layout_centerInParent="true"
            android:textSize="17sp"
            android:text="查看物流"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RelativeLayout>

    <TextView
        android:background="#b9b3b3"
        android:layout_width="match_parent"
        android:layout_height="1dp" />

    <android.support.v7.widget.RecyclerView
        android:layout_marginTop="10dp"
        android:padding="15dp"
        android:id="@+id/express_recyview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Recyclerview的适配器ExpressRecyAdapter

public class ExpressRecyAdapter extends RecyclerView.Adapter<ExpressRecyAdapter.ExpressViewHolder> {

   List<ExpressBean.ResultBean.ListBean> expressBeanList;
    Context context;
    public ExpressRecyAdapter(Context context, List<ExpressBean.ResultBean.ListBean> expressBeanList) {
        this.context = context;
        this.expressBeanList = expressBeanList;
    }

    @Override
    public ExpressViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.express_item_layout,null,false);
        return new ExpressViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ExpressViewHolder holder, final int position) {
      if (position==expressBeanList.size()-1){//如果是最后一个条目,隐藏掉竖线
            holder.item_shuxian.setVisibility(View.GONE);
         }

         holder.item_day.setText(expressBeanList.get(position).getDate());
         holder.item_time.setText(expressBeanList.get(position).getTime());
         holder.item_content.setText(expressBeanList.get(position).getRemark());
        }

    @Override
    public int getItemCount() {
        return expressBeanList.size();
    }


    public static class ExpressViewHolder extends RecyclerView.ViewHolder {

        private final ImageView item_shuxian;
        private final TextView item_day;
        private final TextView item_time;
        private final TextView item_content;

        public ExpressViewHolder(View itemView) {
            super(itemView);
            //找id
            item_shuxian = itemView.findViewById(R.id.item_shuxian);
            item_day = itemView.findViewById(R.id.item_day);
            item_time = itemView.findViewById(R.id.item_time);
            item_content = itemView.findViewById(R.id.item_content);
        }
    }
}

我这里是自己造的数据,模型类ExpressBean

public class ExpressBean {
    
    /**
     * resultcode : 200
     * reason : 查询物流信息成功
     * result : {"company":"EMS","com":"ems","no":"1186465887499","status":"1","list":[{"datetime":"2016-06-15 21:44:04","remark":"离开郴州市 发往长沙市【郴州市】","zone":""},{"datetime":"2016-06-15 21:46:45","remark":"郴州市邮政速递物流公司国际快件监管中心已收件(揽投员姓名:侯云,联系电话:)【郴州市】","zone":""},{"datetime":"2016-06-16 12:04:00","remark":"离开长沙市 发往贵阳市(经转)【长沙市】","zone":""},{"datetime":"2016-06-17 07:53:00","remark":"到达贵阳市处理中心(经转)【贵阳市】","zone":""},{"datetime":"2016-06-18 07:40:00","remark":"离开贵阳市 发往毕节地区(经转)【贵阳市】","zone":""},{"datetime":"2016-06-18 09:59:00","remark":"离开贵阳市 发往下一城市(经转)【贵阳市】","zone":""},{"datetime":"2016-06-18 12:01:00","remark":"到达  纳雍县 处理中心【毕节地区】","zone":""},{"datetime":"2016-06-18 17:34:00","remark":"离开纳雍县 发往纳雍县阳长邮政支局【毕节地区】","zone":""},{"datetime":"2016-06-20 17:55:00","remark":"投递并签收,签收人:单位收发章 *【毕节地区】","zone":""}]}
     * error_code : 0
     */

    private String resultcode;
    private String reason;
    /**
     * company : EMS
     * com : ems
     * no : 1186465887499
     * status : 1
     * list : [{"datetime":"2016-06-15 21:44:04","remark":"离开郴州市 发往长沙市【郴州市】","zone":""},{"datetime":"2016-06-15 21:46:45","remark":"郴州市邮政速递物流公司国际快件监管中心已收件(揽投员姓名:侯云,联系电话:)【郴州市】","zone":""},{"datetime":"2016-06-16 12:04:00","remark":"离开长沙市 发往贵阳市(经转)【长沙市】","zone":""},{"datetime":"2016-06-17 07:53:00","remark":"到达贵阳市处理中心(经转)【贵阳市】","zone":""},{"datetime":"2016-06-18 07:40:00","remark":"离开贵阳市 发往毕节地区(经转)【贵阳市】","zone":""},{"datetime":"2016-06-18 09:59:00","remark":"离开贵阳市 发往下一城市(经转)【贵阳市】","zone":""},{"datetime":"2016-06-18 12:01:00","remark":"到达  纳雍县 处理中心【毕节地区】","zone":""},{"datetime":"2016-06-18 17:34:00","remark":"离开纳雍县 发往纳雍县阳长邮政支局【毕节地区】","zone":""},{"datetime":"2016-06-20 17:55:00","remark":"投递并签收,签收人:单位收发章 *【毕节地区】","zone":""}]
     */

    private ResultBean result;
    private int error_code;

    public String getResultcode() {
        return resultcode;
    }

    public void setResultcode(String resultcode) {
        this.resultcode = resultcode;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public ResultBean getResult() {
        return result;
    }

    public void setResult(ResultBean result) {
        this.result = result;
    }

    public int getError_code() {
        return error_code;
    }

    public void setError_code(int error_code) {
        this.error_code = error_code;
    }

    public static class ResultBean {
        private String company;
        private String com;
        private String no;
        private String status;
        /**
         * datetime : 2016-06-15 21:44:04
         * remark : 离开郴州市 发往长沙市【郴州市】
         * zone :
         */

        private List<ListBean> list;

        public String getCompany() {
            return company;
        }

        public void setCompany(String company) {
            this.company = company;
        }

        public String getCom() {
            return com;
        }

        public void setCom(String com) {
            this.com = com;
        }

        public String getNo() {
            return no;
        }

        public void setNo(String no) {
            this.no = no;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public static class ListBean {
            private String date;
            private String time;
            private String remark;
            private String zone;

            public ListBean(String date,String time, String remark, String zone) {
                this.date = date;
                this.time = time;
                this.remark = remark;
                this.zone = zone;
            }


            public String getDate() {
                return date;
            }

            public void setDate(String date) {
                this.date = date;
            }

            public String getTime() {
                return time;
            }

            public void setTime(String time) {
                this.time = time;
            }

            public String getRemark() {
                return remark;
            }

            public void setRemark(String remark) {
                this.remark = remark;
            }

            public String getZone() {
                return zone;
            }

            public void setZone(String zone) {
                this.zone = zone;
            }
        }
    }
}

适配器中引入的条目布局express_item_layout.xml

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

    <LinearLayout
        android:paddingBottom="20dp"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView
        android:textColor="#cccccc"
        android:textSize="11sp"
        android:text="2018-12-29"
        android:id="@+id/item_day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

        <TextView
            android:textColor="#cccccc"
            android:textSize="11sp"
            android:text="21:44:05"
            android:id="@+id/item_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <ImageView
            android:src="@drawable/icon_wuliu"
            android:layout_width="20dp"
            android:layout_height="20dp" />

        <ImageView
            android:id="@+id/item_shuxian"
            android:background="#CCCCCC"
            android:layout_width="1dp"
            android:layout_height="match_parent"/>
    </LinearLayout>

    <TextView
        android:paddingBottom="25dp"
        android:textSize="12sp"
        android:text="离开长沙市 发往贵阳市(经转)【长沙市】"
        android:id="@+id/item_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

 

发布了110 篇原创文章 · 获赞 32 · 访问量 7万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览