I reached a good solution with this:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:top="-1dp" android:right="-1dp" android:left="-1dp"> <shape> <solid android:color="@android:color/transparent" /> <stroke android:width="1dp" android:color="#ffffff" /> </shape> </item> </layer-list>
This works well if you need a transparent background , but still the color of the open stroke (in my case, I only need the bottom line). If you need a background color, you can add a solid shape color, as in Maryβs answer.
EDIT 1
Sometimes for high-density devices, the use of low immersion values ββcan result in very thin or invisible strokes or distances. This can happen to you when setting ListView delimiters.
The simplest workaround is to use 1px distance instead of 1dp. This will make the line always visible at all densities. The best solution would be to create measurement resources for each density to get the best size for each device.
Edit 2
Fun, but I tried to use this after 6 years, and I can't get a good result on Lollipop devices.
Perhaps the current solution is to use the 9 patch. Android should have easily solved this problem after this time.
htafoya Dec 14 '11 at 9:01 2011-12-14 09:01
source share