1

Please advice how to place an image as background for LinearLayout so this image would look as is, not stretched, titled or something.

Eugene
  • 59,186
  • 91
  • 226
  • 333

3 Answers3

4

Other solution is to define your image in a XML and refer to this XML on your background as explained here : Background Image Placement
Like that you can control your image (background) layout

Community
  • 1
  • 1
Plumillon Forge
  • 1,659
  • 1
  • 16
  • 31
0

Jojo's solution might work if the content of Linear layout is smaller than image height. if i add two or edit text automatically the image starts stretching. if u still want to avoid and make the imageview at background use the below xml layout.

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <ImageButton android:id="@+id/imageButton1" android:src="@drawable/icon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@null"></ImageButton>
    <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="100px"></Button>
</RelativeLayout>

Because only image button has the src options that remains constant to width and height of image.

Jana
  • 2,890
  • 5
  • 35
  • 45
-2

make android height and width of LinearLayout into wrap_content using this code in .xml file

android:layout_height="wrap_content"  
android:layout_width="wrap_content"  

to set background to the image use code

android:background="@drawable/image"

Now place the image in the drawable file

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
ShineDown
  • 1,881
  • 3
  • 21
  • 29
  • 2
    He asks how to make sure the image is not stretched. With your solution, if the content of the linear layout becomes larger than the image, then the image will be stretched again. How do you solve that ? –  Feb 04 '14 at 16:58