Basically I created a background.xml to add the background image to preserve the aspect ratio. Then I set the background of the ImageView
to @drawable/background
.
How could I change the background image from the Activity?
In activity_main.xml:
<ImageView
android:scaleType="centerCrop"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:id="@+id/imageView1"
android:layout_alignTop="@+id/scrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/background"
android:src="@drawable/gradient"/>
In background.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="fill"
android:src="@drawable/image" />
@drawable/image
is the actual .jpg file