1

I have a RecyclerView set to a vertical GridLayoutManager

shelfRecyclerView.setLayoutManager(new GridLayoutManager(getContext(),2));

elements inside the recyclerview have fixed width and height using sdp so the horizontal divider width is fixed too.

enter image description here

is there any way to get the width of the horizontal divider and set the vertical divider width as the same as that?

Anthraxff
  • 148
  • 1
  • 13
  • For divider to be same your item's height has to be same as `RecyclerView` excluding horizontal margins . – ADM Feb 13 '21 at 06:16

1 Answers1

2

You can achieve this by implementing a custom ItemDecoration which adds equal horizontal and vertical space to each item. Here are some samples to get you started
Decorating RecyclerView (with GridLayoutManager) to display divider between items
https://gist.github.com/UweTrottmann/c6344c32aa61d1bec5a6

Amin Mousavi
  • 1,220
  • 10
  • 21