首页 > 解决方案 > 如何创建自定义可绘制对角渐变

问题描述

我想创建附加图像中显示的背景渐变。

目前我正在使用这个 xml,它没有提供所需的效果:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="225"
        android:endColor="#FF5C1E"
        android:startColor="#A300F3"
        android:type="linear"
        android:useLevel="false" />
</shape>

请帮帮我。 在此处输入图像描述

标签: androidxmlandroid-layoutandroid-drawable

解决方案


应该使用radial类型gradient来使用它,您应该coordinates XY设置centerXcenterY最后 对于半径使用此字段。gradientRadius

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:centerX="0.9"
        android:centerY="0.1"
        android:endColor="#FF5C1E"
        android:gradientRadius="1700"
        android:startColor="#A300F3"
        android:type="radial" />
</shape>

推荐阅读