Skip to content Skip to sidebar Skip to footer

How To Indent The Divider In A Linear Layout Recyclerview (ie, Add Padding, Margin, Or An Inset Only To The Itemdecoration)

Following this answer I was able to get a divider between the items of a vertical RecyclerView. However, I also wanted to slightly indent the divider lines. I was able to do it by

Solution 1:

Use inset

drawable/my_divider.xml

<insetxmlns:android="http://schemas.android.com/apk/res/android"android:insetLeft="40dp"android:insetRight="40dp" ><shape><sizeandroid:height="1dp"/><solidandroid:color="@color/recyclerview_divider" /></shape></inset>

Using the constructor that takes a resource id as shown in this answer, we can supply the id of our custom divider xml file.

recyclerView.addItemDecoration(
        newDividerItemDecoration(getActivity(), R.drawable.my_divider));

enter image description here

Post a Comment for "How To Indent The Divider In A Linear Layout Recyclerview (ie, Add Padding, Margin, Or An Inset Only To The Itemdecoration)"