How to make two parallel and adjacent lines in Android xml?

I am trying to create my own list separator. It has one horizontal line in which there is a thin gradient and a second horizontal white line immediately below it, as a kind of “shadow”.

I am trying to use <layer-list>what I want to accomplish, but it does not work as I expect.

Here is the code:

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape>
            <gradient
                android:startColor="#ccd0d3"
                android:centerColor="#b6babd"
                android:endColor="#ccd0d3"
                android:height="1px"
                android:angle="0" />
        </shape>
    </item>

    <item android:top="2px">        
        <shape
            android:color="@android:color/white"
            android:height="1px" />
    </item>


</layer-list>

If I use android:dividerto assign this ListViewand set android:dividerHeight="2", I get a gray gradient that has two highs. The white line is nowhere to be seen.

If I set the white line android:top="1px", I will see a gray gradient with one pixel and one black black line below it.

Any ideas what I'm doing wrong?

+3
1

dividerHeight 3 .

0

Source: https://habr.com/ru/post/1721352/


All Articles