RecyclerView用法

来源:互联网 发布:linux命令行查看文件 编辑:程序博客网 时间:2024/06/10 14:48

一、简述




二、代码示例

1.建立item视图:


2.继承RecyclerView.Adapter<MyviewHolder>





3、主布局 导入本地sdk中axtras/android/support/v7/recycleerView/libs的v7包





添加分隔线


分隔线类
DividerItemDecoration 
https://gist.github.com/alexfu/0f464fc3742f134ccd1e


动画效果源码参考

https://github.com/gabrielemariotti/RecyclerViewItemAnimators


自定义线的主题颜色, drawable文件夹新建 shape类型的divider_02.xml文件,gradient是设置渐变色;在value和value-v14中的style.xml文件添加item style



使用notifyItemInserted方法来更新界面,pos位置将会混乱,若获取位置应使用holder.getLayoutPosition()方法




变身gridview


删除动画


添加监听事件的方法

adapter里面定义接口,声明该接口的参数,提供一个给参数赋值的方法


在onbindviewholder方法内部触发该接口




在mainactivity 中调用该回调接口



设置点击变色样式,drable文件新建selector标签的xml文件,不能直接添加颜色,需要在values文件下Androidxml定义颜色,然后设置背景为该selector文件






0 0