繁体   English   中英

如何使用 XML 制作双渐变(类似iphone)

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

如何使用 XML 制作这种可绘制渐变?

双渐变图像

我可以做一个从颜色 A 到颜色 B 的简单渐变,但我不知道如何在同一个可绘制对象中组合两个渐变。

我终于找到了一个对我来说足够好的带有层列表的解决方案:

<?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>

中间设置为 20 sp,因为容器的高度为 40sp,但您可以通过编辑来调整: android:bottom="20sp"

您可以在渐变中拥有三个 colors。 开始颜色、结束颜色和中心颜色。

<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"] />

或者,您可以使用 LayerList Drawable 并将它们拼凑在一起。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM