>我有一个ImageButton
,我想填充它的父RelativeLayout
容器的宽度,但减去几个dp
,所以它有一些左右填充。我尝试fill_parent-10dp
但这会导致错误并且无法呈现。
在 ImageButton 上放一个android:layout_margin="10dp"
,以及
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- 使用 xml 属性
android:layout_marginLeft
指定额外的视图左侧的空间。 - 使用 xml 属性
android:layout_marginRight
指定视图右侧的额外空间。 - 使用 xml 属性
android:layout_marginTop
指定额外的视图顶部的空间。 - 使用 xml 属性
android:layout_marginBottom
指定视图底部的额外空间。 - 使用 xml 属性
android:layout_margin
指定额外的视图左侧、顶部、右侧和底部的空间。
在您的情况下,您的 ImageButton 声明如下所示
<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"