Android - only the last item is displayed in the layer list

I am trying to create a divider style for a ListView . I want only two simple horizontal lines.

list.xml

 <ListView android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/ListView" > </ListView> 

styles.xml

 <style name="ListView" parent="android:style/Widget.ListView"> <item name="android:divider">@drawable/divider</item> <!-- 5dp: just to make sure there enough space --> <item name="android:dividerHeight">5dp</item> </style> 

divider.xml

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#00ffff" /> <size android:height="1dp" /> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="#ff0000" /> <size android:height="1dp" /> </shape> </item> </layer-list> 

The result is a horizontal line with height of 5dp (it should be 2, right?) And color of red (color of the second element). The first item with color #00ffff not displayed at all.

Can someone suggest a code for 2 simple horizontal lines?

+4
source share
1 answer

I’d better answer my question ...

It seems that styles.xml - style - item displays the color of the last item in the layer-list as the background for the entire separator. This last item is on top of other layers , so other items in the list of layers are not displayed.

Key padding .

styles.xml

 <style name="ListView" parent="android:style/Widget.ListView"> <item name="android:divider">@drawable/divider</item> <item name="android:dividerHeight">10dp</item> </style> 

divider.xml

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#0000ff" /> <padding android:top="5dp"/> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="#ff0000" /> </shape> </item> </layer-list> 

divider

So in my case, I just need to change 10dp / 5dp to 2dp / 1dp to get two thin horizontal lines.

+11
source

All Articles