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?

有帮助吗?

解决方案

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>

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top