標籤:
http://blog.csdn.net/worker90/article/details/6893246
相對布局對於做Web開發來說再熟悉不過了,我們在用CSS+DIV的時候經常會用到這些類似的相對布局的,在設定某個DIV的位置的時候,我們時常會以一個DIV作為參考來設定的位置,廢話不多說,直接看屬性看執行個體。
|
屬性名稱 |
描述 |
|
android:layout_below |
擺放在指定組件的下邊 |
|
android:layout_toLeftOf |
擺放在指定組件的左邊 |
|
android:layout_toRightOf |
擺放在指定組件的右邊 |
|
android:layout_alignTop |
以指定組件作為參考進行上對齊 |
|
android:layout_algnBottom |
以指定組件作為參照進行下對齊 |
|
android:layout_alignLeft |
以指定組件作為參考進行靠左對齊 |
|
android:layout_alignRight |
以指定組件 |
以上一節的例子再做一個相對布局實現的例子
相對布局對於做Web開發來說再熟悉不過了,我們在用CSS+DIV的時候經常會用到這些類似的相對布局的,在設定某個DIV的位置的時候,我們時常會以一個DIV作為參考來設定的位置,廢話不多說,直接看屬性看執行個體。
|
屬性名稱 |
描述 |
|
android:layout_below |
擺放在指定組件的下邊 |
|
android:layout_toLeftOf |
擺放在指定組件的左邊 |
|
android:layout_toRightOf |
擺放在指定組件的右邊 |
|
android:layout_alignTop |
以指定組件作為參考進行上對齊 |
|
android:layout_algnBottom |
以指定組件作為參照進行下對齊 |
|
android:layout_alignLeft |
以指定組件作為參考進行靠左對齊 |
|
android:layout_alignRight |
以指定組件 |
以上一節的例子再做一個相對布局實現的例子
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_toRightOf="@+id/tv_username"
android:id="@+id/txt_username">
</EditText>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/txt_username"
android:layout_alignLeft="@+id/txt_username"
android:layout_alignParentRight="true" android:id="@+id/txt_password"></EditText>
<TextView android:id="@+id/tv_username" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="使用者名稱稱"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_marginTop="14dp"></TextView>
<Button android:text="登入" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/txt_password"
android:layout_alignParentRight="true" android:layout_alignLeft="@+id/txt_password"
android:id="@+id/btn_login"></Button>
<Button android:text="取消" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/txt_password"
android:layout_alignRight="@+id/tv_username" android:id="@+id/btn_cacel"></Button>
<TextView android:id="@+id/tv_password" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="使用者密碼"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/txt_password"></TextView>
</RelativeLayout>
執行個體效果:
執行個體效果:
從頭學Android之RelativeLayout相對布局