RelativeLayout裡面各個控制元件對齊問題
舉例
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