Reputation: 60184
Please advice how to place an image as background for LinearLayout
so this image would look as is, not stretched, titled or something.
Upvotes: 1
Views: 9836
Reputation: 1879
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
Upvotes: -2
Reputation: 2920
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.
Upvotes: 0
Reputation: 1643
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
Upvotes: 4