For a long time, I was searching for a nice way to display horizontal and vertical dividers to a
RecyclerView with a
I tried custom decorators, adding padding and margin inside the cells and so much more different approaches. The correct one is so simple it’s even disappointing.
First of all — define the divider:
<?xml version="1.0" encoding="utf-8"?>
Then just use the
DividerItemDecoration that comes with the
Just like that:
val verticalDecorator = DividerItemDecoration(Activity, DividerItemDecoration.Vertical)
val horizontalDecorator = DividerItemDecoration(Activity, DividerItemDecoration.Horizontal)
val drawable = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.divider, Theme)
Yes, you read it correctly. Just create two decorators: one for horizontal and one for the vertical axis, and that’s it.
Have a nice day.