有没有办法在Android RelativeLayout中填充父减去固定数字



>我有一个ImageButton,我想填充它的父RelativeLayout容器的宽度,但减去几个dp,所以它有一些左右填充。我尝试fill_parent-10dp但这会导致错误并且无法呈现。

在 ImageButton 上放一个android:layout_margin="10dp",以及

android:layout_width="fill_parent"
android:layout_height="fill_parent"
  1. 使用 xml 属性android:layout_marginLeft指定额外的视图左侧的空间。
  2. 使用 xml 属性android:layout_marginRight指定视图右侧的额外空间。
  3. 使用 xml 属性 android:layout_marginTop 指定额外的视图顶部的空间。
  4. 使用 xml 属性android:layout_marginBottom指定视图底部的额外空间。
  5. 使用 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"

最新更新