如何使基于角的渐变可绘制

问题描述 投票:2回答:1

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

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参数不适用于线性渐变。此渐变是否有任何起点/终点参数?感谢您的帮助!

android android-layout android-xml
1个回答
0
投票

我尝试过的最佳方法

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

然后将TextView和Tick图标包装在布局内,并为其设置以上背景。

[如果您希望获得与图像中提供的效果完全相同的效果,则最好为其使用图像或矢量文件。。但是,方法是将背景设置为仅包装的布局而不是根,这是相同的。

© www.soinside.com 2019 - 2024. All rights reserved.