Recyclerview实现展开、折叠分组,多种布局,多种divider

使用方式

compile 'com.wanjian:expandable-recyclerview:0.0.1'

分组RecyclerView

支持多种group布局和多种child布局

[图片上传失败...(image-d09ed6-1518181457487)]

继承NestedAdapter,实现下列方法即可,跟使用ExpandableListview类似,getGroupItemViewType可以和getChildItemViewType相同,但必须都要大于0


    protected abstract int getGroupCount();

    protected abstract int getChildCount(int groupIndex);

    protected int getGroupItemViewType(int groupIndex) {
        return 1;
    }

    protected int getChildItemViewType(int groupIndex, int childIndex) {
        return 1;
    }

    protected abstract G onCreateGroupViewHolder(ViewGroup parent, int viewType);

    protected abstract void onBindGroupViewHolder(G holder, int groupIndex);

    protected abstract C onCreateChildViewHolder(ViewGroup parent, int viewType);

    protected abstract void onBindChildViewHolder(C holder, int groupIndex, int childIndex);


为NestedAdapter添加divider

[图片上传失败...(image-14906d-1518181457487)]

支持添加头部,尾部,group间,child间,group和child间添加自定义divider


 public NestedAdapterDivider setDividerBetweenGroup(Drawable dividerBetweenGroup)  

    public NestedAdapterDivider setDividerBetweenChild(Drawable dividerBetweenChild)  

    public NestedAdapterDivider setDividerBetweenGroupAndChild(Drawable dividerBetweenGroupAndChild)  

    public NestedAdapterDivider setDividerBeforeFirstGroup(Drawable dividerBeforeFirstGroup) 

    public NestedAdapterDivider setDividerAfterLastGroup(Drawable dividerAfterLastGroup)  


展开折叠Recyclerview

[图片上传失败...(image-fc030c-1518181457487)]

继承自ExpandableAdapter即可,调用如下方法实现展开折叠,同样支持多种group布局和多种child布局



    public void collapseGroup(int groupIndex) 

    public void expandGroup(int groupIndex)  

    public boolean isExpand(int groupIndex) 
    
    public void collapseAllGroup()  
    

支持局部刷新,局部移除添加

相关方法如下


    public void notifyGroupItemChanged(int groupIndex)  

    public void notifyGroupChanged(int groupIndex)  

    public final void notifyChildItemChanged(int groupIndex, int childIndex)  

    public final void notifyChildItemRangeChanged(int groupIndex, int childIndex, int itemCount)  

    public final void notifyChildItemInserted(int groupIndex, int childIndex)  
    
    public final void notifyChildItemRangeInserted(int groupIndex, int childIndex, int itemCount)  

    public final void notifyChildItemRemoved(int groupIndex, int childIndex)  

    public final void notifyChildItemRangeRemoved(int groupIndex, int childIndex, int itemCount) 

Github地址

https://github.com/android-notes/expandable-recyclerview/edit/master/README.md

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,539评论 25 709
  • 内容抽屉菜单ListViewWebViewSwitchButton按钮点赞按钮进度条TabLayout图标下拉刷新...
    皇小弟阅读 46,957评论 22 665
  • 原文链接:https://github.com/opendigg/awesome-github-android-u...
    IM魂影阅读 33,026评论 6 472
  • 这一个星期,我玩的时间有点太长了, 作业却很少。只做了语文第一单元的听写、练了毛笔字、把第五周的、第六周的和第七周...
    小溪流32号闪亮阅读 497评论 0 0
  • 岗台中心园规范办园行为自查报告 为了进一步提高我园的保教质量,办人民满意的幼儿园,根据《未成年人保护法》、...
    赵建欣阅读 392评论 0 0