如何在android中的相对布局底部锚定一个按钮

Tor*_*ups 5 layout android relativelayout

我是android的布局结构的新手,我的任务是构建一个底部有一个按钮的活动(也是居中的水平),在按钮底部和可见底部之间有一点点填充屏幕.

挑战在于如何在相对布局中执行此操作,并使其无论屏幕大小如何都锚定到同一位置

如果有人能指出我正确的方向,这将是伟大的!

Pat*_*fka 10

开发文档有一些样品布局和API演示项目是伟大的.

下面的布局会将按钮放在底部,但请记住,当您向相对布局添加更多控件时,它们必须相互尊重.比如layout_above这个按钮或者把这个按钮放在最后并确保它有一个像android这样的属性:layout_below ="id_of_other_bottommost_controll"

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" >

<Button 
        android:layout_height="wrap_content" android:layout_width="fill_parent" 
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:text="button"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)