How to make RecyclerView#39;s grid item to have equal height and width?(如何使 RecyclerView 的网格项具有相等的高度和宽度?)
问题描述
我通过使用跨度计数为 3 的 GridLayoutManger
设置其布局,将我的 RecyclerView
定义为网格,这已经可以正常工作了.我还在我的回收站视图中添加了一个项目装饰器,它将管理网格项目之间的间距,这也可以正常工作.
I define my RecyclerView
as grid by setting its layout with GridLayoutManger
that has a span count of 3 which are already working fine. I also add an item decorator to my recycler view which will manage the spacing between grid items, this also works fine.
我为我的回收站视图添加项目装饰的实现:
My implementation for adding item decoration to my Recycler View:
我的网格项目 xml 布局:
My grid item xml layout :
通过在网格项之间添加空格将调整网格项的宽度,这可能会导致无法获得我的项目视图的比例大小.我想要获得的是动态调整我的网格项高度等于它的宽度.我该怎么做?
By adding spaces between grid item will adjust the grid item's width which can possibly cause of not getting the proportion size of my item view. What I want to obtain is to resize my grid item height equal to its width dynamically. How can I do it?
推荐答案
我已经使用 ConstraintLayout
完成了这个:
I've done this using ConstraintLayout
:
这篇关于如何使 RecyclerView 的网格项具有相等的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!