5

I am trying to use layer-list to create a gradient stroke (i.e. perimeter/border) as the background of my view. But it's not working.

Here is my code

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <gradient
                android:angle="270"
                android:centerColor="#FFFFFFFF"
                android:endColor="#FFCCCCCC"
                android:startColor="#FFCCCCCC"
                android:type="linear" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#F0F1F3" />

            <margin
                android:bottom="4dp"
                android:left="4dp"
                android:right="4dp"
                android:top="4dp" />
        </shape>
    </item>

</layer-list>

The first item is not visible at all. only the second item fills the screen. Any thoughts on how to fix this?

4

2 回答 2

22

也许这可以使用,它会产生一些阴影效果

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Drop Shadow Stack -->
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#00CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#10CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#20CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#30CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <corners android:radius="12dp" />

            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#50CCCCCC" />
        </shape>
    </item>

    <!-- Background -->
    <item>
        <shape>
            <solid android:color="@android:color/black" />

            <corners android:radius="12dp" />
        </shape>
    </item>

</layer-list>
于 2013-07-25T07:16:49.113 回答
10

你可以试试这样的

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape
        android:innerRadius="80dp"
        android:shape="ring"
        android:thickness="20dp"
        android:useLevel="false">
        <size
            android:width="200dp"
            android:height="200dp" />
        <gradient
            android:endColor="#00ff0000"
            android:gradientRadius="200"
            android:startColor="#ffff0000"
            android:type="radial" />
    </shape>
</item>
<item
    android:bottom="20dp"
    android:left="20dp"
    android:right="20dp"
    android:top="20dp">
    <shape android:shape="oval">
        <stroke
            android:width="1dp"
            android:color="#ff0000" />
    </shape>
</item>
</layer-list>

在此处输入图像描述

于 2017-08-23T09:24:36.337 回答