I have an ImageButton
that I want to fill its parent RelativeLayout
container for its width but minus a few dp
so it has some left and right padding. I tried fill_parent-10dp
but that causes an error and doesn't render.
Asked
Active
Viewed 2.3k times
36

Onik
- 19,396
- 14
- 68
- 91

Anthony Frizalone
- 589
- 1
- 6
- 15
-
3what about _padding_ and _margin_? – K-ballo Jun 23 '12 at 02:16
2 Answers
47
Put a android:layout_margin="10dp"
on the ImageButton, along with the
android:layout_width="fill_parent"
android:layout_height="fill_parent"

you786
- 3,659
- 5
- 48
- 74
10
- Use the xml attribute
android:layout_marginLeft
to specifies extra space on the left side of your view. - Use the xml attribute
android:layout_marginRight
to specifies extra space on the right side of your view. - Use the xml attribute
android:layout_marginTop
to specifies extra space on the top side of your view. - Use the xml attribute
android:layout_marginBottom
to specifies extra space on the bottom side of your view. - Use the xml attribute
android:layout_margin
to specifies extra space on the left, top, right and bottom sides of your view.
In your case your ImageButton declaration look like this
<ImageButton
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Button"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:src="@drawable/a"

K_Anas
- 31,226
- 9
- 68
- 81