Introduction to RecyclerViewRecyclerView在Android 5中被介绍,在 Support-V7的包中。她允许展示items在随意任何之处(可联想ListView),正如包名所说的,在API7以上均可使用(Android 22). 她的名 ...
Introduction to RecyclerView
RecyclerView在Android 5中被介绍,在 Support-V7的包中。她允许展示items在随意任何之处(可联想ListView),正如包名所说的,在API7以上均可使用(Android 22).
她的名字来自于其工作的方式,当一个Item被隐藏时,不是去destroyed她并且随后为每一个新new出来的对象去创建一个新的item,隐藏的item被回收:她们被重用,并且会有新的数据绑定她们。
一个RccyclerView被分为6个主要的组件:
an Adpter,提供数据(类似Listview的)
an ItemAnimator, 负责items的修改,增加,删除,移动的动画效果
an ItemDecoration, Which can add drawings or change the layout of an item
an Layoutmanage,指定Items的布局
an ViewHolder, 每一个Items View的基类
the RecyclerView本身, 把所有的绑定
在support-V7包中,一些组件已经绑定了默认的实现方式。你有一个ItemAnimator和三个Layoutmanage可以玩玩。RecyclerView不需要修改,并且ItemDecoration是可选的,留给我们的还有Adpter和ViewHolder。
Display a RecyclerView
1.Prepare your project
add to your dependenceies:
RecyclerView: compile 'com.android.support:recyclerview-v7:22.2.1'
CardView: compile 'com.android.support:cardview-v7:22.2.1'
2.The bass item
我们写一个简单的list,每一个items里包含一个 title 和 一个 subtitle。
1 public class Item{ 2 private String title; 3 private String subtitle; 4 5 public Item(String title,String subtitle){ 6 this.title = title; 7 this.subtitle = subtitle; 8 } 9 10 public String getTitle(){11 return title;12 }13 14 public String getSubtitle(){15 return subtitle;16 }17 }
原标题:Android自学历程—RecyclerView的使用(2)
关键词:Android
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。