【问题标题】:Is there a way to fill parent minus a fixed number in Android RelativeLayout?有没有办法在Android RelativeLayout中填充父母减去固定数字?
【发布时间】:2012-06-25 08:17:02
【问题描述】:

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

【问题讨论】:

  • paddingmargin 怎么样?

标签: android android-relativelayout android-imagebutton fill-parent


【解决方案1】:

在 ImageButton 上加上 android:layout_margin="10dp" 以及

android:layout_width="fill_parent"
android:layout_height="fill_parent"

【讨论】:

    【解决方案2】:
    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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      • 2019-11-18
      • 1970-01-01
      • 2021-06-27
      相关资源
      最近更新 更多