ImageView/Shape Drawable not rotating in landscape

83 Views Asked by At

I'm using an image view with its source pointing to a shape drawable for the background for my app. I want it to look like this which is in the layout preview (blue on the top, orange on the bottom). enter image description here

However, whenever I run it, it looks like this. It's basically the portrait version, so it isn't being rotated. I use android:screenOrientation="landscape" in activity tag in the manifest to force it into landscape.enter image description here

This is the code for the image view in my layout, as well as the 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>

I've tried to use the rotate attribute in the layout to set it to 90 degrees, but it doesn't come out quite as well.enter image description here

Anyone know how to try to get my background looking like it's supposed to in the preview?

2

There are 2 best solutions below

0
On BEST ANSWER

Had to manually adjust the gradient angle in the shape drawable XML itself. Set angle to 90, swap start and end gradient colours.

0
On
 <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>