I want someone to know what he is doing, and not just copy random answers from the Internet
Well, you will not do anything better than the nine paths:

The 9 patch above has a yellow 0.5dp (base xhdpi) frame 0.5dp (base xhdpi) for illustration. The upper and left fences (black lines) define the stretchable area.
Please note that the security line on the right works completely, from end to end. This means that there will be no gasket at the top and bottom. But the protective line at the bottom begins with the leftmost pixels and ends just before the yellow border. When you set this 9patch to listview, the bottom guard line will indent 0.5dp (the width of the yellow border) to the right.
However, this approach requires some work. You will need to create as many 9x drawings as possible, as there are buckets. If you need a border of 0.5dp, the width of the yellow border will be different for each bucket:
xxxhdpi: 2 px xxhdpi: 1.5 px xhdpi: 1 px hdpi: 0.75 px .... and so on
9patch drawing details: Link
Another approach (already suggested here) is to use View to act as a border. In this case, the easiest layout (not mentioned here) is to use a FrameLayout and place the ListView and border inside it:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="0.5dp" android:background="#E7E7E7" android:choiceMode="singleChoice" android:dividerHeight="0.5dp" /> <View android:layout_width="0.5dp" android:layout_height="match_parent" android:layout_gravity="right" android:background="@color/some_color"/> </FrameLayout>
In this case, you will get ViewGroup and View as decorations. 9patch would be the best solution. Make your choice.
source share