【问题标题】:ImageView/Shape Drawable not rotating in landscapeImageView/Shape Drawable 不横向旋转
【发布时间】:2021-05-18 22:24:47
【问题描述】:

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

但是,每当我运行它时,它看起来都是这样的。它基本上是纵向版本,所以它没有被旋转。我在清单的活动标签中使用 android:screenOrientation="landscape" 来强制它进入横向。

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

   <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 度,但效果不佳。

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

【问题讨论】:

  • 安装了这个应用程序:srcCompat="@drawable/background" 使用 android:background=""
  • 还是不行。

标签: android rotation imageview android-shapedrawable


【解决方案1】:

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

【讨论】:

    【解决方案2】:
     <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多