So i am using RecyclerView
with GridLayoutManager
the spacing between the items is not consistent around the item
This is how it looks in 4 x 4 Grid
This is how it looks in 5 x 5 grid
I already tried many solution from this and this and this
But nothing worked for me
Here is my how i am setting my adapter
mLayoutManager = new GridLayoutManager(mContext, 5);
mRecyclerView.setLayoutManager(mLayoutManager);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.spacing);
mRecyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
And this is my SpacesItemDecoration
class
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpacesItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view,RecyclerView parent, RecyclerView.State state)
{
outRect.left = space;
outRect.right = space;
outRect.top = space;
outRect.bottom = space;
// Add top margin only for the first item to avoid double space between items
if (parent.getChildLayoutPosition(view) == 0)
{
outRect.top = space;
}
else
{
outRect.top = 0;
}
}
}
I don't know why it is not working for me
There is no margin or padding to my recyclerview & item