RecyclerView Grid-定义每行中的项目数 [英] RecyclerView Grid - define number of items per row in

查看:372
本文介绍了RecyclerView Grid-定义每行中的项目数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常反对发布没有代码的问题,但是我没有要显示的代码.我终于将项目从列表视图和网格视图转换为recyclerView.在一个课程中,我使用一个小的gridview放置从服务器提取的项目.

每行的最大项目数为3,但其余部分需要排在最前面.因此,如果有5个项目,则第一行有2个,底部有3个.如果有4个项目,则第一行有1个,底部有3个.

我的google-fu失败了,我无法找到这种自定义类型的任何示例.如果有人可以向我指出正确的方向,我将把我完整的代码发布给以后找到这篇文章的人.

谢谢

解决方案

有一个 解决方案

There is a constructor of GridLayoutManager, that takes four parameters.

new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, true)

the second one is the spanCount, the number of columns or rows in the grid, while the forth is called reverseLayout and when set to true, the cells are laid out from the end to the start .

这篇关于RecyclerView Grid-定义每行中的项目数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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