在Android中,只有0、90、180和270度是预定义的角度,可以直接使用。如果你想要使用其他角度,可以通过创建一个自定义的drawable资源来实现。

首先,创建一个名为gradient_angle.xml的XML文件,并将其放置在res/drawable目录中。然后,将以下代码添加到gradient_angle.xml文件中:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#FF0000"
        android:endColor="#0000FF"
        android:angle="30"
        android:type="linear" />
</shape>

在这个示例中,我们将开始颜色设置为红色(#FF0000),结束颜色设置为蓝色(#0000FF),并将角度设置为30度。

然后,在你的布局文件中,将这个自定义的drawable资源作为背景应用到你想要使用渐变的视图上,如下所示:

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient_angle" />

这样,你就可以在Android上使用30度的渐变角度了。

Android gradient angle指定30度没有效果 只有0、90、180、270、有效果

原文地址: https://www.cveoy.top/t/topic/jclO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录