我如何将此渐变放在XML资源中?

时间:2014-12-11 11:20:10

标签: android xml gradient

这是一个简单的问题,但我不知道该怎么做。

渐变有两个部分,结果是这个。

Gradient

生成的代码是下一个,但我不知道如何将只有一个XML用作背景。

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient 
android:type="linear"
android:centerX="30%" 
android:startColor="#00ffffff" 
android:centerColor="#FFffffff" 
android:endColor="#00ffffff" 
android:angle="0"/>
</shape>

-------------------------------------------------
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient 
android:type="radial"
android:centerX="50%" 
android:centerY="50%" 
android:startColor="#00ffffff" 
android:centerColor="#FFffffff" 
android:endColor="#00ffffff" 
android:gradientRadius="30"/>
</shape>

谢谢

修改

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:type="linear"
                android:centerX="30%"
                android:startColor="#00ffffff"
                android:centerColor="#FFffffff"
                android:endColor="#00ffffff"
                android:angle="0"/>
        </shape>
    </item>

    <item>
        <shape android:shape="rectangle" >
            <gradient
                android:type="radial"
                android:centerX="50%"
                android:centerY="50%"
                android:startColor="#00ffffff"
                android:centerColor="#FFffffff"
                android:endColor="#00ffffff"
                android:gradientRadius="30"/>
        </shape>
    </item>
</layer-list>

RESULT

Result

1 个答案:

答案 0 :(得分:2)

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <gradient 
                android:type="linear"
                android:centerX="30%" 
                android:startColor="#00ffffff" 
                android:centerColor="#FFffffff" 
                android:endColor="#00ffffff" 
                android:angle="0"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle" >
            <gradient 
                android:type="radial"
                android:centerX="50%" 
                android:centerY="50%" 
                android:startColor="#00ffffff" 
                android:centerColor="#FFffffff" 
                android:endColor="#00ffffff" 
                android:gradientRadius="30"/>
        </shape>
    </item>
</layer-list>

有关图层列表(和其他)here

的更多信息