How to get rid of gaps between GridLayoutManager items

Viewed 130

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?

enter image description here

1 Answers

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

Related