I came across a scenario where I needed to customize the split line of the listView, which is made up of two lines, and I was having trouble using XML drawable.

Note: Two lines are drawn to achieve the effect of depression. a dark line followed by an obvious one in the drawing gives the visual impression of a distinct “trench”.

Since my background is transparent (gradient background), using images directly doesn’t look good.

 

Look at the results:

 

Use layer-list to do this.

Layer-list can contain multiple items, each stacked on top of the other.

Layer-list items can set spacing, using properties like Android :bottom.

 

Specific practices:

1. Draw the first line.

2. Set the second line 1px apart from the head so it doesn’t overlap completely

3. The two cables are stacked

 

The specific code is as follows.

<? The XML version = "1.0" encoding = "utf-8"? > <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="0px" android:left="0px"  android:right="0px" android:top="0px"> <shape android:shape="rectangle" > <size android:height="1px" android:width="1px" /> <solid android:color="#A18249" /> </shape> </item> <item android:bottom="0px" android:left="0px" android:right="0px" android:top="3px"> <shape android:shape="rectangle" > <size android:height="2px" android:width="2px"  /> <solid android:color="@android:color/white" /> </shape> </item> </layer-list>Copy the code

 

Reference: stackoverflow.com/questions/1…