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

查看:50
本文介绍了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天全站免登陆