android 如何使一条线可以用渐变绘制?

js81xvg6  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(113)

所以...我想添加一条类似于line with gradient的线,并创建了一个可绘制的

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="90">
    <shape
        android:shape="line">

        <stroke
            android:color="#000000"
            android:width="1dp"/>
        <gradient android:startColor="#FFEE8D85"
            android:endColor="#000000"/>
    </shape>
</rotate>

它给出了line without gradient,我该怎么做才能得到我想要的结果呢?

nbysray5

nbysray51#

制作可绘制的资源文件。

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:type="linear"
        android:angle="90"
        android:startColor="#14b19e"
        android:endColor="#115ede" />
</shape>

然后像这样涂抹

<View
    android:layout_width="1dp"
    android:layout_height="50dp"
    android:background="@drawable/my_gradient_drawable"/>

相关问题