android layer list won't show both a gradient and a solid

erosebe picture erosebe · Jun 28, 2013 · Viewed 7.1k times · Source

I don't understand what is going on with this code.

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

<item android:bottom="10dp">
    <shape android:shape="rectangle" >
        <solid android:color="#ff8898A4" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <gradient
            android:angle="90"
            android:endColor="#ffD6DDD8"
            android:startColor="#ffB1BBC3" />
    </shape>
</item>
</layer-list>

If I move the solid below the gradient the gradient doesn't show. But the way it is now the solid won't show. I didn't have any trouble with two solid. What am I doing wrong?

Answer

Nick picture Nick · Jun 28, 2013

You are placing the solid shape item over the gradient shape item.

You need to add some padding to the gradient shape. You are doing the opposite adding the padding to the solid shape versus the gradient shape, try this:

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

<item>
    <shape android:shape="rectangle" >
        <solid android:color="#ff8898A4" />
    </shape>
</item>
<item android:bottom="10dp">
    <shape android:shape="rectangle" >
        <gradient
            android:angle="90"
            android:endColor="#ffD6DDD8"
            android:startColor="#ffB1BBC3" />
    </shape>
</item>
</layer-list>