I'm having this RecyclerView
configured with a layout manager as:
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
My specific case is that the child items don't have a predefined width. Instead, I set their width to
android:layout_width="match_parent"
And then I expect the GridLayoutManager
to give each item 1/3 of the available space.
So far so good, but I want that if in the last row there are only 1 or 2 items to show, I want to center them.
I tried this solution but what I get is:
As you can see in the last row, the items are streched to the edges of the layout and the parent 's width is divided between them. This happens because as I said, their width is not predifined.
What I expect is to calculate the items width, as they were shown 3 items per row, and then center them. As in this image:
Is there any way how can I make this with GridLayoutManager
or even with FlexboxLayoutManager
?