Android之RecyclerView实现时光轴
来源:互联网 发布:阿松手办淘宝 编辑:程序博客网 时间:2024/06/05 10:05
做项目的过程中有个需求需要时光轴,于是网上找了部分资料 ,写了个案例,现在分享给大家。
如图:
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'
由于代码太多,完整代码未给出,源码直接下载即可
源码点击下载
0 0
- Android之RecyclerView实现时光轴
- RecyclerView实现时光轴效果
- 时光轴二之RecyclerView版时光轴效果
- 自定义recyclerView实现时光轴效果
- 《Android 时光轴实现》
- 时光轴一之listView实现时光轴效果
- android listview 实现时光轴效果
- 使用RecyclerView实现电商物流信息的时光轴效果
- 简易时光轴实现
- 【Android】时光轴效果
- Android 中轴时光轴
- Android时光轴
- Android开发之实现RecyclerView万能适配器
- Android---RecyclerView之简单瀑布流实现
- androidd时光轴效果实现
- Android 时光轴 -记录生活
- Android-RecyclerView 实现步骤
- 时光轴三之 ExpandableListView版时光轴效果
- python如何实现快速的求和函数
- 题目:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数。
- class、extends、super
- 数据结构实验之栈五:下一较大值(一)
- Java开发环境搭建
- Android之RecyclerView实现时光轴
- 基础练习 特殊的数字
- mac系统下.../Users/***Library/为什么进入Finder找不到Library目录?
- Jmeter正则表达式提取
- python DataFrame 修改列的顺序
- InputStreamReader 和FileReader的区别及InputStream和Reader的区别
- LintCode 30:Insert Interval
- 【初等概率论】 02
- Android 展开、收起