【发布时间】:2020-12-09 10:55:38
【问题描述】:
我有 7 个元素(这里以简化的方式)。如何设置网格布局以制作 2 列布局,其中前 4 个元素位于 column1 上,其余元素位于 column2 上。 像这样
1 5
2 6
3 7
4
我正在使用带有 GridLayout 的回收器视图
val itemDecoration = ItemOffsetDecoration(8)
recycler_view.layoutManager = GridLayoutManager(context, 2)
recycler_view.adapter = MyAdapter(context, items)
recycler_view.addItemDecoration(itemDecoration)
【问题讨论】:
-
可能正在使用自定义布局管理器
-
@Raghunandan 你能解释更多吗,如果可能的话,请分享任何例子。
-
类似:public void onBindViewHolder(final BadgeViewHolder holder, int position) { // Pair -> left column if (position % 2 == 0 ){ itemdecorator.get(position); }else{ int computePosition = position = offset + (position / 2) - 1; itemdecorator.get(位置);其中 offset 是计算数据结构的大小和网格布局管理器中的行数(大小 / nbrOfRow 四舍五入到上限值)。
-
您找到解决方案了吗?
-
@AyxanHaqverdili 还没有。
标签: android kotlin android-recyclerview adapter gridlayoutmanager