问题描述
我有2列的RecyclerView和GridLayoutManager.如何强制LayoutManager与第一个屏幕截图上的模板保持一致?现在,我得到的结果与第二张屏幕截图相同.
I have a RecyclerView and GridLayoutManager with 2 columns.How can I force LayoutManager to be according with template on the first screenshot? Now I have result as on the 2th screenshot.
需要的结果:
当前结果:
推荐答案
GridLayoutManager
将使用网格,并且您可以设置一些跨度,但为不同的单元格设置不同的高度.
GridLayoutManager
will use a grid, and you can set some span, but not different heights for different cells.
您想要的是 StaggeredGridLayoutManager
.如果适合的话,这只会将它们放在屏幕上,从而导致您所需的结果.您还可以根据需要使用更改重新排序行为. setGapStrategy
.
What you want is a StaggeredGridLayoutManager
. This will just put the items on the screen if they fit, leading to your needed result. You can also change the reordering behavior, if you want to, by using setGapStrategy
.
这篇关于GridLayoutManager中不同的(动态)项目高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!