像Instagram搜索一样实现非对称网格布局管理器
问题描述:
我创建了一个RecyclerView
并将我的适配器的layoutManager
设置为GridLayout
.
但我想要GridLayout
像Instagram搜索一样,如下图所示,
I Created a RecyclerView
And Set layoutManager
Of My Adapter To GridLayout
.
But I Want GridLayout
Like Instagram Search below image,
我想要这样的GridView
:
请帮助我.谢谢 .
我尝试了SpanSizeLookup,但是我仍然遇到问题,并且我无法控制我的项目以这种方式进行布局. .
i tried SpanSizeLookup But i Have Still My Problem And i Cant Control My Items to laying out exactly that way . . .
答
并在跨度"中显示您的列表
and for show Your list in Span
val manager = SpannedGridLayoutManager(object : SpannedGridLayoutManager.GridSpanLookup{
override fun getSpanInfo(position: Int): SpannedGridLayoutManager.SpanInfo {
// Conditions for 2x2 items
return if (position % 12 == 0 || position % 12 == 7) {
SpannedGridLayoutManager.SpanInfo(2, 2)
} else {
SpannedGridLayoutManager.SpanInfo(1, 1)
}
}
},3/*column*/,1f/*how big is default item*/)
binding.feedHome.setHasFixedSize(true)
binding.feedHome.layoutManager = manager
binding.feedHome.adapter = adapter
此图像帮助您如何计算显示大图像中的项目
and this image help you how to calculate item in show big image