带有 RecyclerView 的可扩展列表? [英] Expandable list with RecyclerView?

查看:24
本文介绍了带有 RecyclerView 的可扩展列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在新的 RecyclerView 中使用可扩展的列表项吗?喜欢 ExpandableListView?

It's possible to use expandable list items with new RecyclerView? Like ExpandableListView?

推荐答案

这对于现有的 LayoutManager 来说很简单,这完全取决于您如何管理适配器.

This is simple to do with the stock LayoutManagers, it all depends on how you manage your adapter.

当您想扩展一个部分时,您只需在标题之后向您的适配器添加新项目.请记住在执行此操作时调用 notifyItemRangeInserted.要折叠一个部分,您只需删除相关项目,然后调用 notifyItemRangeRemoved().对于适当通知的任何数据更改,回收器视图将为视图设置动画.添加项目时,会创建一个区域以填充新项目,新项目淡入.删除则相反.除了适配器之外,您需要做的就是设置视图样式以将逻辑结构传达给用户.

When you want to expand a section you just add new items to your adapter after the header. Remember to call notifyItemRangeInserted when you do this. To collapse a section you simply remove the relevant items, and call notifyItemRangeRemoved(). For any data changes that are appropriately notified, the recycler view will animate the views. When adding items, an area to be filled with the new items is made, with the new items fading in. Removal is the opposite. All you need to do besides the adapter stuff is to style your views to convey the logical structure to the user.

更新:Ryan Brooks 现在写了一个 关于如何执行此操作的文章.

Update: Ryan Brooks has now written an article on how to do this.

这篇关于带有 RecyclerView 的可扩展列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆