0

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

但是,每当我运行它时,它看起来像这样。它基本上是纵向版本,所以它没有被旋转。我在清单的活动标签中使用 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 度,但效果不佳。在此处输入图像描述

任何人都知道如何尝试让我的背景看起来像它应该在预览中?

4

2 回答 2

0
 <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>
于 2021-02-16T06:07:39.767 回答
0

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

于 2021-02-16T06:12:57.410 回答