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

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

用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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • keil4注册机注册不了怎么办?我已经试过下面的注册机不行。求各大神指教一下?

    keil4注册机注册不了怎么办?我已经试过下面的注册机不行。求各大神指教一下?

    2022年5月13日
    53
  • 2021Eclipse最新下载与安装教程

    2021Eclipse最新下载与安装教程2021Eclipse下载与安装教程具体步骤如下:1.下载Eclipse软件下载可以在Eclipse官方下载,也可以在国内镜像地址下载。由于Eclipse官方地址服务器在国外,下载速度比较慢,国内镜像地址下载速度会快很多。1.1官方下载官方下载地址:https://www.eclipse.org/downloads/packages/release.访问官方下载地址。如下所示:在这里插入图片描述点击要下载的版本,以2018-09为例,进入下面窗口,选择Rpackages在这里插入图

    2022年6月3日
    35
  • 三十而立,从零开始学ios开发

    三十而立,从零开始学ios开发三十而立,从零开始学ios开发(二十):ApplicationSettingsandUserDefaults(下)摘要:在上一篇的学习中,我们知道了如何为一个App添加它的Settings设置项,在Settings设置项中我们可以添加哪些类型的控件,这些控件都是通过一个plist来进行管理的,我们只需对plist进行修改添加,就可以映射到Settings中。但是在上一篇中

    2022年5月18日
    41
  • redis :read error on connection

    redis :read error on connection

    2021年10月27日
    33
  • 项目管理书籍推荐「建议收藏」

    项目管理书籍推荐「建议收藏」人人都是产品经理作为一名北漂,我的同事郝文鹏曾经总结过一些自己的经验,现无私分享出来,希望能帮到你:IT项目管理作为项目管理的子集,建议先看一些项目管理的书籍作为基础。基础类:《项目管理:计划.进

    2022年8月4日
    3
  • redux-saga_pub culture

    redux-saga_pub culture本文用以记录从调研ReduxSaga,到应用到项目中的一些收获。什么是ReduxSaga官网解释来自:https://github.com/redux-saga/redux-sagaredux-sagaisalibrarythataimstomakesideeffects(i.e.asynchronousthingslikedatafetchingand…

    2022年9月19日
    0

发表回复

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

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