Question

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?

Was it helpful?

Solution

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>

OTHER TIPS

The second rectangle covers the first completely. Items in a layer-list are drawn on top of each other beginning with the first. If the don't have any offset, they all have the same size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top