使用方式
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
网友评论