举例
xml文件如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_login"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/log_box"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/et_login_pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et_login_name"
android:layout_marginBottom="12dp"
android:layout_marginLeft="110dp"
android:background="@drawable/shuru"
android:ems="10"
android:password="true" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/tv_login_forget_pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et_login_pwd"
android:layout_marginLeft="120dp"
android:text="@string/str_forget_pwd"
android:textColor="@color/branse"
android:textStyle="bold"
android:textSize="20dp" />
<Button
android:id="@+id/btn_login_regist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="56dp"
android:layout_marginTop="75dp"
android:layout_toRightOf="@+id/btn_login_login"
android:background="@drawable/xml_regist_btn" />
<Button
android:id="@+id/btn_login_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/et_login_pwd"
android:background="@drawable/xml_login_btn" />
<EditText
android:id="@+id/et_login_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/et_login_pwd"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/et_login_pwd"
android:layout_marginBottom="20dp"
android:background="@drawable/shuru"
android:ems="10" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
下图是按照UI设计出来的效果图
对于RelativeLayout 控件不熟悉
曾经参考
数据类型 | 常量名称 | 描述 |
int | ABOVE | 定义将元素的底边对齐另一个元素的顶边 |
int | ALIGN_BASELINE | 定义将元素基线的对齐另一个元素的基线 |
int | ALIGN_BOTTOM | 定义将元素底边的对齐另一个元素的底边 |
int | ALIGN_LEFT | 定义将元素的左边对齐另一个元素的左边 |
int | ALIGN_PARENT_BOTTOM | 定义将元素的底边对齐其父容器(RelativeLayout)的底边 |
int | ALIGN_PARENT_LEFT | 定义将元素的左边对齐其父容器(RelativeLayout)的左边 |
int | ALIGN_PARENT_RIGHT | 定义将元素的右边对齐其父容器(RelativeLayout)的右边 |
int | ALIGN_PARENT_TOP | 定义将元素的顶边对齐其父容器(RelativeLayout)的顶边 |
int | ALIGN_RIGHT | 定义将元素的右边对齐另一个元素的右边 |
int | ALIGN_TOP | 定义将元素的顶边对齐另一个元素的顶边 |
int | BELOW | 定义将元素的顶边对齐另一个元素的底边 |
int | CENTER_HORIZONTAL | 定义让元素在容器(RelativeLayout)内水平居中 |
int | CENTER_IN_PARENT | 定义让元素位于容器(RelativeLayout)的中心 |
int | CENTER_VERTICAL | 定义让元素在容器(RelativeLayout)内垂直居中 |
int | LEFT_OF | 定义将元素的右边对齐另一个元素的左边 |
int | RIGHT_OF | 定义将元素的左边对齐另一个元素的右边 |
int | TRUE |
http://www.cnblogs.com/over140/archive/2011/01/26/1945083.html