lundi 29 juin 2015

Change background image of drawable resource

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://ift.tt/nIICcg"
    android:gravity="fill"
    android:src="@drawable/image" />

@drawable/image is the actual .jpg file

Aucun commentaire:

Enregistrer un commentaire