2

Recycler view item decoration not equally spaced when span count is odd. When I set even span, the spacing looks equal but when set odd span count the middle column spacing is little bit disturbed. How to resolve this issue? The code is:

final int spacing = getResources().getDimensionPixelSize(R.dimen.recycler_spacing);
// apply spacing
recyclerView.setPadding(spacing, spacing, spacing, spacing);
recyclerView.setClipToPadding(false);
recyclerView.setClipChildren(false);
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(spacing, spacing, spacing, spacing);
}
});

Screenshot

Junaid Khan
  • 315
  • 5
  • 16

1 Answers1

0

You can add margin in your row xml for equal spacing in your recyclerview. Its the easy way to add equal spacing between your list items.

ahmad bajwa
  • 966
  • 2
  • 10
  • 30