Android之RecyclerView实现时光轴效果示例

 更新时间:2017年02月15日 14:43:22   作者:切切歆语  
本篇文章主要介绍了Android之RecyclerView实现时光轴效果,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

做项目的过程中有个需求需要时光轴,于是网上找了部分资料 ,写了个案例,现在分享给大家。

如图:

       

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  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/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never" />

</RelativeLayout>

item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="8dp"
  android:paddingRight="8dp"
  android:paddingTop="8dp">
  <TextView
    android:id="@+id/item_timeline_time"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginRight="8dp"
    android:layout_marginTop="18dp"
    android:gravity="center_horizontal"
    android:padding="4dp"
    android:textColor="@color/colorAccent"
    android:textSize="16sp"
    android:text="2015-06-08\n09:56"
    />

  <RelativeLayout
    android:id="@+id/item_timeline_icon_layout"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_marginBottom="4dp"
    android:layout_marginRight="8dp"
    android:layout_toRightOf="@id/item_timeline_time">

    <com.timelinedemo.CircleImageView
      android:id="@+id/item_timeline_icon_bg"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@android:color/transparent"
      app:civ_border_width="4dp" />

    <ImageView
      android:id="@+id/item_timeline_icon"
      android:layout_width="24dp"
      android:layout_height="24dp"
      android:layout_centerInParent="true"
      android:scaleType="fitCenter" />

  </RelativeLayout>

  <TextView
    android:id="@+id/item_timeline_content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="18dp"
    android:layout_toRightOf="@id/item_timeline_icon_layout"
    android:text="今日收入"
    android:textColor="@color/colorPrimary"
    android:textSize="15sp" />

  <TextView
    android:id="@+id/item_timeline_money"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/item_timeline_content"
    android:layout_marginTop="8dp"
    android:layout_toRightOf="@id/item_timeline_icon_layout"
    android:text="$ 100"
    android:textColor="@color/colorPrimary"
    android:textSize="22sp" />
  <View
    android:id="@+id/item_timeline_view"
    android:layout_width="2dp"
    android:layout_height="60dp"
    android:layout_alignLeft="@id/item_timeline_icon_layout"
    android:layout_below="@id/item_timeline_icon_layout"
    android:layout_marginLeft="23dp"
    android:background="@color/colorAccent" />
</RelativeLayout>

Activity.Java

public class MainActivity extends AppCompatActivity {

  private RecyclerView recyclerView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initLayout();
  }
  private void initLayout(){
    recyclerView= (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    initData();
  }
  private void initData(){
    List<TimeInfo > list=new ArrayList<>();
    for(int i=0;i<15;i++){
      list.add(new TimeInfo());
    }
    TimelineAdapter mAdapter = new TimelineAdapter(this, list);
    recyclerView.setAdapter(mAdapter);
  }
}

添加依赖库:

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

由于代码太多,完整代码未给出,源码直接下载即可

源码点击下载:TimeLineDemo_jb51.rar

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Android中对xml文件解析的3种方式总结

    Android中对xml文件解析的3种方式总结

    这篇文章主要给大家介绍了关于Android中对xml文件解析的3种方式,分别是 Dom 、 SAX 和 dom4j,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。
    2018-02-02
  • Android 实现页面跳转

    Android 实现页面跳转

    android使用Intent来实现页面跳转,接下来通过本文给大家分享Android 实现页面跳转的实例代码,需要的的朋友参考下吧
    2017-09-09
  • Android性能优化之捕获java crash示例解析

    Android性能优化之捕获java crash示例解析

    这篇文章主要介绍了Android性能优化之捕获java crash示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-09-09
  • Android debug包运行正常release包崩溃的解决办法

    Android debug包运行正常release包崩溃的解决办法

    这篇文章主要介绍了Android debug包运行正常,release包崩溃解决办法,文中通过代码示例介绍的非常详细,对大家解决问题有一定的帮助,需要的朋友可以参考下
    2024-04-04
  • Android仿淘宝头条向上滚动广告条ViewFlipper

    Android仿淘宝头条向上滚动广告条ViewFlipper

    这篇文章主要为大家详细介绍了Android仿淘宝头条向上滚动广告条ViewFlipper,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-05-05
  • Presenting Streams in Flutter小技巧

    Presenting Streams in Flutter小技巧

    这篇文章主要为大家介绍了Presenting Streams in Flutter小技巧示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-12-12
  • 深入探究Android动态代理的原理及用途

    深入探究Android动态代理的原理及用途

    动态代理是一种在编程中非常有用的设计模式,它允许你在运行时创建一个代理对象来代替原始对象,以便在方法调用前后执行额外的逻辑,本文将深入探讨Android动态代理的原理、用途和实际示例
    2023-09-09
  • Android中使用GridView实现仿微信图片上传功能(附源代码)

    Android中使用GridView实现仿微信图片上传功能(附源代码)

    由于工作要求最近在使用GridView完成图片的批量上传功能,我的例子当中包含仿微信图片上传、拍照、本地选择、相片裁剪等功能,如果有需要的朋友可以看一下
    2017-08-08
  • Android仿支付宝微信支付密码界面弹窗封装dialog

    Android仿支付宝微信支付密码界面弹窗封装dialog

    这篇文章主要介绍了Android仿支付宝微信支付密码界面弹窗封装dialog的实例代码,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-03-03
  • 手把手教你用Android自定义饼状图

    手把手教你用Android自定义饼状图

    最近在项目中需要用到简单的饼形图统计,我们就没必要去找什么开源的,可以尝试自己画一下。现在将实现的过程分享给大家,有需要的朋友们可以参考借鉴,下面来一起看看吧。
    2016-10-10

最新评论