I have a LinearLayout
which has a background image (a 9 patched png file). How can I add padding to left and right so that the background image does not take up the whole width? I have tried android:paddingLeft
and android:paddingRight
, but that does not change anything.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="25dip" android:paddingRight="25dip" android:background="@drawable/background">
The whole background still stretches the whole screen width.
In the File Properties dialog, select the Appearance tab. In the Padding section, enter numbers in the Left, Right, Top, and/or Bottom fields to set the width of the padding (in pixels). Click OK. The padding is added to the image, displayed in the default background color of the image.
Selective Padding However, you can add padding selectively by using padding-bottom, padding-left, padding-right, and padding-top. Here are a few examples: style="padding-left: 10px; padding-bottom: 20px;"
The padding-box value means that the only the padding box part of the HTML element has the background image rendered. The content-box value means that the only the content box part of the HTML element has the background image rendered.
You should use xml drawable, specially designed for this purposes - Inset Drawable: http://developer.android.com/guide/topics/resources/drawable-resource.html#Inset
For example:
res/drawable/inset_background.xml:
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/your_background_image" android:insetRight="25dip" android:insetLeft="25dip" />
and then in your xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/inset_background">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With