從頭學Android之RelativeLayout相對布局

來源:互聯網
上載者:User

標籤:

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相對布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.