RecyclerView LayoutManager“一对一"作为Sololearn的级别菜单 [英] RecyclerView LayoutManager "one two one" as Sololearn's levels menu
本文介绍了RecyclerView LayoutManager“一对一"作为Sololearn的级别菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使LinearLayout管理器像这样:
How can we made LinearLayout manager like this:
我还检查了线性和网格管理器,但在这种情况下,我们似乎需要新的东西.
I also have checked Linear and Grid managers but it seems that in this case we need something new.
推荐答案
我在本主题中发现了同样的问题,并使其符合我的问题:
I found the same problem in this topic and just make it fit my question:
RecyclerView LayoutManager在不同行上的不同跨度计数
我们只需创建 GridLayoutManager
并覆盖方法,然后简单地在Recycler中对其进行设置:
We just create GridLayoutManager
and override method, then simplity set it in Recycler:
val layoutManager = GridLayoutManager(context, 2)
layoutManager.spanSizeLookup = object : SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
// 5 is the sum of items in one repeated section
when (position % 3) {
0 -> return 2
1, 2 -> return 1
}
throw IllegalStateException("internal error")
}
}
recycler.layoutManager = layoutManager
这篇关于RecyclerView LayoutManager“一对一"作为Sololearn的级别菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文