如何消除GridLayoutManager项目之间的间隙

huangapple go评论93阅读模式
英文:

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?

如何消除GridLayoutManager项目之间的间隙

答案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).

Code example

huangapple
  • 本文由 发表于 2020年8月3日 00:58:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63218743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定