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.
Functionally no difference, Google just changed the name from fill_parent to match_parent, from API level 8 (Android 2.2).
MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. Introduced in API Level 8.
fill_parent and match_parent are the same, used when we want the height or width of a view to be as big as its parent view, fill_parent being deprecated. wrap_content is used when we want the view to occupy only as much space as required by it.
Below that, the layout_height=0 and layout_weight=1 attributes on the RelativeLayout cause it to take up all the remaining space. You can then center the button in the RelativeLayout . You can play with padding on the button to get it to the size you want.
Put a android:layout_margin="10dp"
on the ImageButton, along with the
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft
to specifies extra
space on the left side of your view.android:layout_marginRight
to specifies
extra space on the right side of your view.android:layout_marginTop
to specifies extra
space on the top side of your view.android:layout_marginBottom
to specifies
extra space on the bottom side of your view.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"
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