开发者

How to make a double gradient with XML (iphone like)

开发者 https://www.devze.com 2023-03-19 15:48 出处:网络
How can I make this kind of drawable gradient with XML? I can do a simple gradient from color A to color B but i don\'t know how to combine two 开发者_JS百科gradients in the same drawable.I finall

How can I make this kind of drawable gradient with XML?

How to make a double gradient with XML (iphone like)

I can do a simple gradient from color A to color B but i don't know how to combine two 开发者_JS百科gradients in the same drawable.


I finally found a solution with a layer-list which is good enough for me :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- First part is a gradient -->
    <item android:left="0dp" android:right="0dp"> 
        <shape android:shape="rectangle">

            <gradient android:angle="-90" android:startColor="#9dcbf6"
                android:endColor="#177ee6" />

        </shape>
    </item>
    <!-- Second part is plain color. Slightly transparent -->
    <item android:top="1sp" android:bottom="20sp" > 
        <shape android:shape="rectangle">
            <solid android:color="#10ffffff"/>
        </shape>

    </item>
</layer-list>

The middle is set to 20 sp because the container has a 40sp height , but you can adjust to your will by editing : android:bottom="20sp"


You can have three colors in a gradient. A start color, end color and a center color.

<gradient
        android:angle="integer"
        android:centerX="integer"
        android:centerY="integer"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:usesLevel=["true" | "false"] />

Alternatively you can use a LayerList Drawable and just piece them together.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号