GridLayoutManager中不同的(动态)项目高度 [英] Different (dynamic) items height in GridLayoutManager

查看:516
本文介绍了GridLayoutManager中不同的(动态)项目高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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中不同的(动态)项目高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆