▲ 实现一个简单的快递时间轴效果

▲ 实现一个简单的快递时间轴效果

用RecycleView实现的时间轴效果。
先看一下效果
在这里插入图片描述
【实现思路】

使用一个RecycleView,在item中分成两个部分一部分画这个线,另一部分显示功能布局。其实没有什么难度,重点就在于xml布局中了

【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="wrap_content"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="198dp">

        <RelativeLayout
            android:id="@+id/rl_left"
            android:layout_width="20dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp">

            <TextView
                android:id="@+id/tv_line_a"
                android:layout_width="1px"
                android:layout_height="24dp"
                android:layout_centerHorizontal="true"
                android:background="#ccc" />

            <ImageView
                android:id="@+id/iv_tag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="24dp"
                android:src="@mipmap/icon_a" />

            <TextView
                android:id="@+id/tv_line"
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:layout_below="@+id/iv_tag"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="-1dp"
                android:background="#ccc" />
        </RelativeLayout>

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginRight="26dp"
            android:layout_toRightOf="@+id/rl_left"
            android:background="@mipmap/icon_bg"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="商家同意退款"
                android:textColor="#333"
                android:textSize="18sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="4dp"
                android:text="4天23小时56分 后系统自动退款"
                android:textColor="#999999"
                android:textSize="12sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                android:text="收货人:平平"
                android:textColor="#666"
                android:textSize="14sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="4dp"
                android:text="联系电话:1392XXXXX"
                android:textColor="#666"
                android:textSize="14sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="10dp"
                android:text="2019-08-11 11:36:47"
                android:textColor="#999"
                android:textSize="12sp" />

        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

【业务代码】

public class TimeAdapter extends RecyclerView.Adapter<TimeAdapter.ViewHolderX> {
    private Context mContext;
    private List<String> mList;

    public TimeAdapter(Context context, List<String> list) {
        this.mContext = context;
        this.mList = list;
    }

    @NonNull
    @Override
    public TimeAdapter.ViewHolderX onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_recycler_list, parent, false);
        ViewHolderX viewHoldX = new ViewHolderX(inflate);
        return viewHoldX;
    }

    @Override
    public void onBindViewHolder(@NonNull TimeAdapter.ViewHolderX holder, int position) {
        if (position==0){
            holder.ivTag.setImageResource(R.mipmap.icon_b);
            holder.tvLine_a.setVisibility(View.GONE);
        }else {
            holder.ivTag.setImageResource(R.mipmap.icon_a);
            holder.tvLine_a.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class ViewHolderX extends RecyclerView.ViewHolder {

          TextView tvLine_a;
          TextView tvLine;
          ImageView ivTag;

        public ViewHolderX(@NonNull View itemView) {
            super(itemView);
            tvLine_a = itemView.findViewById(R.id.tv_line_a);
            tvLine = itemView.findViewById(R.id.tv_line);
            ivTag = itemView.findViewById(R.id.iv_tag);
        }
    }
}

可根据自己公司的业务更换Adapter,完善业务。

[希望这篇文章可以帮到你]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/2834.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 冒泡排序深入具体解释

    冒泡排序深入具体解释

    2022年1月26日
    47
  • 正式学习react(二)[通俗易懂]

    正式学习react(二)

    2022年2月22日
    42
  • leetcode 三数之和_leetcode数组

    leetcode 三数之和_leetcode数组原题链接给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。注意:答案中不可以包含重复的三元组。示例 1:输入:nums = [-1,0,1,2,-1,-4]输出:[[-1,-1,2],[-1,0,1]]示例 2:输入:nums = []输出:[]示例 3:输入:nums = [0]输出:[] 提示:0 <= nums.length <= 300

    2022年8月9日
    1
  • document的visibilitychange事件

    document的visibilitychange事件有时,你跑到另外一个页面去,回来发现自己的页面出了个bug,如轮播图写出来当你从别的页面在进去,原先的定时器还是会再运行,这样里面的一些值就会改变,看到的效果就不一样, 下面就是解决这个问题的方法。…

    2022年6月18日
    37
  • Python中时间与时间戳之间的转换

    对于时间数据,如2016-05-0520:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块,具体的操作有如下的几种:将时间转换为时间戳重新格式化时间时间戳转换为时间获取当前时间及将其转换成时间戳1、将时间转换成时间戳将如上的时间2016-05-0520:28:54转换成时间戳,具体的操作过程为:利用strptime

    2022年4月11日
    44
  • java script 下载_JavaScript下载[通俗易懂]

    java script 下载_JavaScript下载[通俗易懂]JavascriptPlus是一个小巧的Javascript脚本辅助编程工具,主要方便开发者对js代码进行测试、预览以及运行等操作,特点包括用不同的颜色显示语法和关键词,有稍许的程序输入预测功能,测试运行子程序等等。JavascriptPlus是一款功能强劲的javascript文本编辑器。内置的智能系统能够提示你-各种Javascript物件、性质和触发事件,-各种Html和Shee…

    2022年6月14日
    25

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号