我有一个
ImageButton
,想要让它的宽度填满其父级 RelativeLayout
容器,但是减去一些 dp
,以便左右留有一些内边距。我尝试使用 fill_parent-10dp
,但这会导致错误并且无法呈现。ImageButton
,想要让它的宽度填满其父级 RelativeLayout
容器,但是减去一些 dp
,以便左右留有一些内边距。我尝试使用 fill_parent-10dp
,但这会导致错误并且无法呈现。在 ImageButton 上加上 android:layout_margin="10dp"
,同时保留
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft
来指定视图左侧额外的空间。android:layout_marginRight
来指定视图右侧额外的空间。android:layout_marginTop
来指定视图顶部额外的空间。android:layout_marginBottom
来指定视图底部额外的空间。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"