Jac*_*cob 64 android margins android-relativelayout
我已经使用了相对布局,我想在屏幕底部设置按钮,但是这会把它全部放到底部,我想有一些余量,所以它在屏幕的末端之间有一些空间/查看和按钮.无论我做什么,按钮边距在2.1+上都没有做任何事情由于某种原因.相对布局包含一个背景,所以我不能但是它的余量.
有人知道解决这个问题吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:background="@drawable/background" >
<Button
android:id="@+id/confirm_mobile_button_next"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_margin="15dp"
android:background="@drawable/button_shape_selector"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="@string/confirm_mobile_no_continue"
android:textColor="@color/white"
android:textStyle="bold" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
And*_*dré 70
您可以简单地向RelativeLayout添加填充而不是Button的边距,例如android:paddingBottom="15dp".
一般来说,我总是使用API Level 8设置在Exclipse预览中测试我的布局.这为大多数设备提供了非常准确的结果,包括ICS和JB.
aja*_*n81 31
你可以做的另一件事就是把View它对齐到底部RelativeLayout,并将它的高度设置为你想要使用的底部边距(或者只是指定一个值layout_marginBottom),如下所示:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/some_image"
android:adjustViewBounds="true"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some Overlay"
android:padding="3dip"
android:gravity="center_vertical|center_horizontal"
android:layout_above="@+id/empty_view"
android:layout_marginBottom="35dip"
/>
<View
android:id = "@+id/empty_view"
android:layout_height = "30dip"
android:layout_width = "match_parent"
android:visibility="invisible"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这个例子填充RelativeLayout用ImageView,并定位TextView在ImageView.
Shu*_*ham 18
Yu可以使用translateY属性
translateY="-16dp"
Run Code Online (Sandbox Code Playgroud)
最终代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:background="@drawable/background">
<Button
android:id="@+id/confirm_mobile_button_next"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_margin="15dp"
android:background="@drawable/button_shape_selector"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="@string/confirm_mobile_no_continue"
android:textColor="@color/white"
android:textStyle="bold"
android:translateY="-16dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82014 次 |
| 最近记录: |