android – 向图层列表添加渐变

如何从背景的右侧和左侧添加渐变阴影?

以下图层列表仅添加背景右侧和左侧的黑色边框,而不是渐变边框.

<?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="0"
                android:centerColor="#ffffff"
                android:endColor="#000000"
                android:startColor="#000000" />
        </shape>
    </item>
    <item
        android:left="2dp"
        android:right="2dp">
        <shape android:shape="rectangle" >
            <solid android:color="@color/blue" />
        </shape>
    </item>
</layer-list>

我试图从背景的右侧和左侧添加黑色阴影.

最佳答案 我不太确定你想要什么,渐变背景或渐变边框?这会给你一个渐变的黑色阴影背景

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <gradient
        android:angle="0"
        android:centerColor="#ffffff"
        android:endColor="#000000"
        android:startColor="#000000" />

</shape>
点赞