Android GridView 有类别吗?
是否可以在 Android 中使用 GridView 中的类别或某种标题?
我快速说明了我的想法:
非常感谢。
Is it possible to use categories or some sort of headers with a GridView
in Android?
I put together a quick illustration of what I was thinking about:
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以直接使用 Stickygridheaders 库或作为模型来创建您自己的小部件。
You can use Stickygridheaders library directly or as a model to create your own widget.
也许此代码会对您有所帮助。这是SectionedGridRecyclerViewAdapter,结果如下所示:
probably this code will help you. This is SectionedGridRecyclerViewAdapter, result looks like this:
我认为你可以做到这一点,但你必须实现 Jeff Shrkey 的 SeparatedListAdapter
I think You can do it but you have to implement Jeff Shrkey's SeparatedListAdapter
您可以修改 Android RecyclerView 以在每行返回一个网格,请参阅此处
添加后,请按照以下步骤创建网格视图:
1. 实现 GridRecyclerViewHelper
首先创建一个实现 GridRecyclerViewHelper 的帮助器类。该类管理标题的创建、标题数据的绑定、网格视图的设置以及网格视图持有者的创建。
GridHeader
类充当普通旧 Java 对象 (POJO),保存有关网格部分标题的信息。2. 为每个网格单元实现 ViewHolder
接下来,实现 GridCellViewHolder 接口以有效地将数据绑定到每种类型的网格单元。
例如,为 actor 单元创建一个专门的 ViewHolder:
You can modify an Android RecyclerView to return a grids at each row see here
Once the library is added, follow these steps to create a grid view:
1. Implement the GridRecyclerViewHelper
Begin by creating a helper class that implements
GridRecyclerViewHelper
. This class manages the creation of headers, the binding of header data, the setup of grid views, and the creation of grid view holders.The
GridHeader
class serves as a Plain Old Java Object (POJO) holding information about grid section headers.2. Implement ViewHolder for Each Grid Cell
Next, implement the
GridCellViewHolder
interface to efficiently bind data to each type of grid cell.For instance, create a specialized ViewHolder for actor cells: