Android自定义View:快递时间轴实现

本文介绍如何在Android中实现自定义的时间轴UI,涉及自定义view基础、RecyclerView及其ItemDecoration的使用。通过创建RecyclerView.Adapter和重写相关方法,详细展示了从布局设计到数据绑定的完整过程。
摘要由CSDN通过智能技术生成

前言

  • 在Android开发中,时间轴的 UI非常常见,如下图:
    TIM图片20190327232833.jpg

  • 储备知识:
    1.自定义view基础
    2.RecyclerView的使用
    3.自定义RecyclerView.ItemDecoration

具体实现

1.最终效果如下:
TIM截图20190327231820.png

2.实现思路

  • 使用RecyclerView,自定义RecyclerView.ItemDecoration
  • 复习ItemDecoration中getItemOffsets()方法,重写onDraw()方法
  • 实现RecyclerView.Adapter,绑定数据

3.详细设计

TIM截图20190327235039.png

TIM截图20190327235010.png

4.具体实现

  • 引入RecyclerView依赖包
dependencies {
     ..........
    api 'com.android.support:recyclerview-v7:28.0.0'
}
  • 在布局文件中使用
<RelativeLayout 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"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="horizontal"
        />


</RelativeLayout>
  • 设置item布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TextView
        android:id="@+id/item_title"
        android:text="New Text"
        android:textSize="15sp"
        android:layout_marginLeft="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值