從零開始學android<RelativeLayout相對布局.十六.>

來源:互聯網
上載者:User

標籤:風飛雪未揚   relativelayout相對布局   android布局   

相對布局管理器指的是參考某一其他控制項進行擺放,可以通過控制,將組件擺放在一個指定參考組件的上、下、左、右等位置,這些可以直接通過各個組件提供的屬性完成。下面介紹一下各個方法的基本使用
No. 屬性名稱 對應的規則常量 描述
1 android:layout_below RelativeLayout.BELOW 擺放在指定組件的下邊
2 android:layout_toLeftOf RelativeLayout.LEFT_OF 擺放在指定組件的左邊
3 android:layout_toRightOf RelativeLayout.RIGHT_OF 擺放在指定組件的右邊
4 android:layout_alignTop RelativeLayout.ALIGN_TOP 以指定組件為參考進行上對齊
5 android:layout_alignBottom RelativeLayout.ALIGN_BOTTOM 以指定組件為參考進行下對齊
6 android:layout_alignLeft RelativeLayout.ALIGN_LEFT 以指定組件為參考進行靠左對齊
7 android:layout_alignRight RelativeLayout.ALIGN_RIGHT 以指定組件為參考進行靠右對齊

<span style="font-size:18px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:textAlignment="center"    tools:context=".MainActivity" >    <EditText        android:id="@+id/editText1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentRight="true"        android:layout_alignParentTop="true"        android:ems="10" />    <EditText        android:id="@+id/editText2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignRight="@+id/editText1"        android:layout_below="@+id/editText1"        android:ems="10"        android:inputType="textPassword" >        <requestFocus />    </EditText>    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBottom="@+id/editText1"        android:layout_alignParentLeft="true"        android:text="帳號" />    <TextView        android:id="@+id/textView2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBottom="@+id/editText2"        android:layout_alignParentLeft="true"        android:text="密碼"        android:textAlignment="center" />    <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/editText2"        android:layout_marginLeft="23dp"        android:layout_marginTop="36dp"        android:layout_toRightOf="@+id/textView2"        android:text="登    錄" />    <TextView        android:id="@+id/textView3"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBottom="@+id/button1"        android:layout_marginLeft="14dp"        android:layout_toRightOf="@+id/button1"        android:autoLink="web"        android:linksClickable="true"        android:text="忘記密碼"        android:textAppearance="?android:attr/textAppearanceSmall"        android:textSize="10dp" /></RelativeLayout></span>

使用相對布局是目前主要的布局方式,它比其他方式都方便快捷,可以再可視化介面直接拖拽即可。

…………………………………………………………毫無美感的分割線…………………………………………………………
使用動態表布局實現和前面的是一樣的,不常使用在這裡不再贅述,有興趣的讀者可以自己嘗試。需要使用以下幾個方法。
1 public RelativeLayout.LayoutParams (int w, int h) 構造 指定RelativeLayout布局的寬度和高度
2 public void addRule (int verb, int anchor) 普通 增加指定的參數規則
3 public int[] getRules () 普通 取得一個組件的全部參數規則



下節預報:使用嵌套布局實現計算機介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.