【问题标题】: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,但这会导致错误并且不会呈现。
【问题讨论】:
标签:
android
android-relativelayout
android-imagebutton
fill-parent
【解决方案1】:
在 ImageButton 上加上 android:layout_margin="10dp" 以及
android:layout_width="fill_parent"
android:layout_height="fill_parent"
【解决方案2】:
- 使用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"