ImageView/Shape 横向绘制不旋转

ImageView/Shape Drawable not rotating in landscape

我正在使用图像视图,其源指向我的应用程序背景的可绘制形状。我希望它在布局预览中看起来像这样(顶部为蓝色,底部为橙色)。

然而,每当我运行它时,它看起来像这样。它基本上是纵向版本,因此不会旋转。我在清单的 activity 标签中使用 android:screenOrientation="landscape" 强制它进入横向。

这是我布局中图像视图的代码,以及 src

   <ImageView
    android:id="@+id/background"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:importantForAccessibility="no"
    android:scaleType="centerCrop"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/background" />

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:centerColor="@color/light_blue_background"
        android:endColor="@color/orange_background"
        android:startColor="@color/teal_background" />
    <size android:height="16dp" />
    <size android:width="32dp" />
</shape>

我尝试在布局中使用旋转属性将其设置为 90 度,但效果不佳。

有人知道如何使我的背景在预览中看起来像预期的那样吗?

 <ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
android:background="@drawable/background" />


<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">
    <gradient
    android:centerColor="@color/light_blue_background"
    android:endColor="@color/orange_background"
    android:startColor="@color/teal_background" />

  </shape>

必须手动调整可绘制形状 XML 本身的渐变角度。将角度设置为 90,交换开始和结束渐变颜色。