RecyclerView妙不可言

来源:互联网 发布:windows to go装win10 编辑:程序博客网 时间:2024/04/29 03:25
 

RecyclerView妙不可言

分类: android 14人阅读 评论(0) 收藏 举报
android

目录(?)[+]

RecyclerView初识

RecyclerView同ListView一样,是可以渲染基于适配器视图的ViewGroup。RecyclerView的灵活性和可替代性远优于ListView。

比较ListView

  • ViewHolder模式强制使用 
    RecyclerView.ViewHolder

  • 自定义布局 
    RecyclerView.LayoutManager允许RecyclerView自定义布局,官方提供了三种LinearLayoutManager、GridLayoutManager、StaggeredGridLayoutManager。 
    参考Two-Ways: 
    http://lucasr.org/2014/07/31/the-new-twowayview/

  • 自定义Item动画 
    RecyclerView.ItemAnimator允许RecyclerView自定义Item动画 
    官方提供了DefaultItemAnimator 
    参考recyclerview-animator: 
    https://github.com/wasabeef/recyclerview-animators 
    https://github.com/gabrielemariotti/RecyclerViewItemAnimators

  • 手动配置数据类型 
    不同于ListView提供不同的数据绑定类型的ArrayAdapter或者CursorAdapter。RecyclerView只提供RecyclerView.Adapter,供用户自定义绑定数据类型

  • 手动配置Item Decoration 
    RecyclerView.ItemDecoration允许RecyclerView自定义Item Decoration 。默认RecyclerView没有Divider分隔线 
    参考DividerItemDecoration 
    https://gist.githubusercontent.com/alexfu/0f464fc3742f134ccd1e/raw/abe729359e5b3691f2fe56445644baf0e40b35ba/DividerItemDecoration.java 
    参考RecyclerView-FlexibleDivider 
    https://github.com/yqritc/RecyclerView-FlexibleDivider

  • 手动配置点击 
    对,RecyclerView没有提供Item click,你需要手动配置 
    参考 
    http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/

其灵活度超乎想象,我们似乎可以创建一个世界一般。

RecyclerView使用

  • Base use 
    hongyang: 
    http://blog.csdn.net/lmj623565791/article/details/45059587 
    codepath: 
    https://github.com/codepath/android_guides/wiki/Using-the-RecyclerView

  • Headerview & Footerview 
    http://www.it165.net/pro/html/201507/48065.html 
    GridLayout的HeaderView 
    http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0722/3214.html

  • With scroll 
    ScrollView与RecyclerView使用,需在ScrollView设置 android:fillViewport=”true” 
    http://stackoverflow.com/questions/25515904/android-recyclerview-inside-a-scrollview

  • Multi Type 
    翻译:http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0810/3282.html 
    github:https://github.com/sockeqwe/AdapterDelegates 
    (非常赞的“组合优于继承”)

(目前写到为止,后续添加) 
demo地址 
http://download.csdn.net/detail/u013211506/9200063

0 0