recyclerview设置行数_RecyclerView Grid-定义每行中的项目数

bd96500e110b49cbb3cd949968f18be7.png

I'm typically against posting a question without code, but I have no code to show. I'm finally converting my project from listviews and gridviews to recyclerView. In one class, I use a small gridview to place items pulled from a server.

The max number of items per row is 3, but the remainder needs to be on top. So if there's 5 items, top row has 2, bottom has 3. If there's 4 items, top row has 1, bottom has 3.

My google-fu is failing me and I'm not able to find any examples with this type of customization. If somebody could point me in the right direction, I'll post my completed code for those who find this post in the future.

Thanks all

解决方案

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 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值