【问题标题】:how to set gradient color to stroke element in layer-list?如何为图层列表中的描边元素设置渐变颜色?
【发布时间】:2019-04-09 09:22:42
【问题描述】:

我使用了两个项目的图层列表。第一项显示渐变颜色,第二项显示具有圆角半径的笔划元素。在这里,我想为描边元素添加渐变颜色。

<?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:endColor="#24615A"
                    android:startColor="#44968C" />
                <corners android:radius="20dp" />
            </shape>
        </item>
        <item>
            <shape android:shape="rectangle">
                <stroke
                    android:width="5dp"
                    android:color="#0AA4F1" />
                <corners android:radius="20dp" />
            </shape>
        </item>
</layer-list>

【问题讨论】:

  • 您的代码是否正常工作或遇到任何问题?
  • 您面临的问题是什么?
  • 我想为描边设置开始颜色和结束颜色,但我只有一个选项来设置描边元素的颜色。

标签: android android-layout gradient xml-drawable


【解决方案1】:

尝试添加另一个矩形,但调整项目填充如下:

<item>
    <shape android:shape="rectangle">

        <gradient
            android:centerColor="#f5e904"
            android:endColor="#ed0f12"
            android:startColor="#479644" />
        <corners android:radius="20dp" />
    </shape>
</item>

<item
    android:bottom="7dp"
    android:left="7dp"
    android:right="7dp"
    android:top="7dp">
    <shape android:shape="rectangle">

        <gradient
            android:endColor="#24615A"
            android:startColor="#44968C" />
        <corners android:radius="20dp" />
    </shape>

</item>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-15
    • 2020-12-12
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-04
    相关资源
    最近更新 更多