渐变色可绘制在 Android 10 上无法正常工作(旋转 90 度)

Noe*_*lia 4 xml android android-layout

我应用了一个渐变可绘制资源作为视图的背景。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
    <gradient
        android:startColor="#cf2aff"
        android:endColor="#5409ff"
        android:type="linear" />
</shape>
Run Code Online (Sandbox Code Playgroud)

在具有Android version < 10它的设备中按预期显示:

渐变背景 1

但是在带有Android 10它的设备中旋转 90 度:

渐变背景 2

有没有人遇到同样的问题并知道如何解决?

Noe*_*lia 9

添加 android:angle="0"

我得到了解决这个问题。您需要设置android:angle属性,即使它是 0 才能使其在Android 10上工作。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
    <gradient
        android:angle="0"
        android:startColor="#cf2aff"
        android:endColor="#5409ff"
        android:type="linear" />
</shape>
Run Code Online (Sandbox Code Playgroud)

我想对于 Android 10,角度默认设置为 90 度。