Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with a layout background image

I am trying to set a image like background image in a layout (by xml or by code)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/my_image">

or

View myLayout= findViewById( R.id.main_layout);
myLayout.setBackgroundResource(R.drawable.my_image);

My problem is than android fix the image in the all background screen, resizing and modifying the image ratio.

How can I set a image, and that the image takes only the neccesary space? (without image resizing)

like image 828
Jose Manuel Avatar asked Mar 29 '11 10:03

Jose Manuel


1 Answers

Without adding an ImageView to the layout, if the image is smaller than the space, you can create an xml bitmap resource like the following, and use this in place of the original background image:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background"
    android:gravity="center"
/>
like image 188
bigstones Avatar answered Sep 20 '22 15:09

bigstones