英文:
How to get rid of gaps between GridLayoutManager items
问题
I'm using RecyclerView
with GridLayoutManager
layout manager.
recyclerView.setLayoutManager(new GridLayoutManager(context, 3))
But since the height of my item layout is wrap_content
, there are some gaps between items.
How do I get rid of them?
英文:
I'm using RecyclerView
with GridLayoutManager
layout manager.
recyclerView.setLayoutManager(new GridLayoutManager(context, 3))
But since the height of my item layout is wrap_content
, there are some gaps between items.
How do I get rid of them?
答案1
得分: 1
我认为使用GridLayoutManager
是不可能的(或者非常困难的)。但是你可以使用:StaggeredGridLayoutManager
一个可以以交错网格形式布局子项的布局管理器。它支持水平和垂直布局,以及以相反的方式布局子项的能力。
交错网格很可能在布局的边缘处有间隙。为了避免这些间隙,StaggeredGridLayoutManager
可以独立地调整跨度或在跨度之间移动项。你可以通过setGapStrategy(int)
来控制这种行为。
英文:
I think it is impossible (or very hard) with GridLayoutManager
. But You can use: StaggeredGridLayoutManager
>A LayoutManager that lays out children in a staggered grid formation. It supports horizontal & vertical layout as well as an ability to layout children in reverse.
>Staggered grids are likely to have gaps at the edges of the layout. To avoid these gaps, StaggeredGridLayoutManager can offset spans independently or move items between spans. You can control this behavior via setGapStrategy(int)
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论