I want to add divider lines in my
Layout. I already searched some time, but I can only find solutions that utilise
RecyclerView.addItemDecoration, which adds the divider between all items. I could create a layout that has a single line and add that to the
RecyclerView, but that doesn’t seem like an elegant solution to me.
You can write a custom
RecyclerView.ItemDecoration and draw divider only where you need. And set it to
This is the default
DividerItemDecoration source code:
You can find the divider drawing logic in
onDraw method, where it draws divider for all items. You have to change that part based on your needs to draw divider for some items only.
getItemOffsets() method adds offset to the item to make space for the divider.
Answered By – Bob