![]() |
[Android UI 設計] [版面布局Layout介紹] RelativeLayout |
大多數情況下,LinearLayout可以幫助我們解決很多UI的布局,不過版面真得過於複雜時,改用RelativeLayout可以大幅降低Layout程式碼的多寡喔!RelativeLayout改用「相對位置」來決定UI元件的布局方式,也就是藉由描述A元件在B元件的對應位置;或描述A元件對應父元件的對應位置。當A元件對應的元件越多,就可以更精準的描述A元件的確切位置。
屬性名稱
|
|
放置在某元件的下方
|
|
放置在某元件的上方
|
|
放置在某元件的左方
|
|
放置在某元件的右方
|
|
對齊某元件的下方
|
|
對齊某元件的右方
|
|
對齊某元件的上方
|
|
對齊某元件的左方
|
|
是否對齊父元件的下方
|
|
是否對齊父元件的左方
|
|
是否對齊父元件的上方
|
|
是否在父元件中水平置中
|
|
是否在父元件中水平置中且垂直置中
|
|
是否在父元件中垂直置中
|
|
<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:background="#adc"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_toLeftOf="@+id/button1"
android:text="CheckBox" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/editText1"
android:text="Button" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/main" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="RelativeLayout"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
![[Android UI 設計] [版面布局Layout介紹] RelativeLayout [Android UI 設計] [版面布局Layout介紹] RelativeLayout](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSX6VzafcRRjnrigvN8yXMC1clJnqfIFXlT3sIoY-14qgdamBbfl_dTUY1Ub6Yyf-ux_o3H2YTmX2iuhIDOcyaatU0dP-0B3s5lL4rWQK40jyzhhLRytIdzG6P9eudhIaUfAAA8xOYY8o/s1600/Snap6.png)
沒有留言 :
張貼留言