Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android background Image to fill screen

How do I get my relative layout to display my image view like this:

enter image description here

Instead of this?:

enter image description here

I want my layout to display as much of the image as it can and crop the outsides of the image, like when you're setting desktop background image to "Fill" in windows:

enter image description here

My xml layout so far:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>

    <LinearLayout
        android:id="@+id/linearLayout1"
        style="@style/SessionResumeBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/home_resumeSessionBar_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Button
            android:id="@+id/home_resumeSessionBar_buttonResume"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Resume" />
    </LinearLayout>





</RelativeLayout>
like image 701
kmb64 Avatar asked May 21 '12 04:05

kmb64


People also ask

What size should android background image be?

The recommended wallpaper image size for a phone is 640 pixels wide X 960 pixels tall. The image has to be either in PNG or JPG format.

How to add background Image to app in Android studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/drawable/app_background. xml. Step 2 − Add the following code to res/values/styles.


2 Answers

Add a scale type to your imageview. There are several types. The one you need is

android:scaleType="center"

This page will help explain all the different types.

like image 70
Phobos Avatar answered Oct 23 '22 13:10

Phobos


Set the ImageView layout parameters to match_parent and set scale type to an appropriate scale type which fulfills your needs:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:scaleType="centerCrop"
    android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>
like image 5
jeet Avatar answered Oct 23 '22 15:10

jeet