首页 > 解决方案 > 如何使基于角的渐变可绘制

问题描述

我正在尝试制作仅放置在右下角的渐变背景。(对不起图片,因为我没有足够的内联代表)

https://i.stack.imgur.com/ebgWn.jpg

首先,我做了径向渐变,但并不完美

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <gradient
        android:centerX="0.9"
        android:centerY="1"
        android:endColor="#00000000"
        android:gradientRadius="40%p"
        android:startColor="#BF000000"
        android:type="radial" />
</shape>

看起来像:

https://i.stack.imgur.com/JOqFf.jpg

然后,我做了线性渐变,但仍然不完美。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <gradient
        android:angle="315"
        android:endColor="#CD000000"
        android:startColor="#00FFFFFF"
        android:type="linear" />
</shape>

https://i.stack.imgur.com/a0y9C.jpg

因为gradientRadius参数不适用于线性渐变。此渐变是否有任何起点/终点参数?感谢帮助!

标签: androidandroid-layoutandroid-xml

解决方案


我试过的最好的

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
        android:centerX="0.8"
        android:centerY="1"
        android:endColor="#00000000"
        android:gradientRadius="80%p"
        android:startColor="#BF000000"
        android:type="radial" />

然后将你和 Tick Icon 包装TextView在一个布局中,并将上面的背景设置为它..

如果您想要与图像中提供的完全相同的效果,那么您最好使用图像或矢量文件。但方法是将背景设置为仅包裹布局而不是根。


推荐阅读