![]() |
[Android UI 設計] 版面布局Layout-LinearLayout |
每一個人第一次接觸到Android UI 設計時,第一個認識的ViewGroup應該都是LinearLayout,因為eclipse自動新增的專案預設就是以「android.widget.LinearLayout 」為主要的版面布局。
LinearLayout是以你設定它的「android:orientation」屬性;值有:垂直(vertical)或水平(horizontal)兩種,用來排列所有的子元件。所有的子元件都被線性堆放在其它元素之後,因此一個設定垂直屬性的每一列只會有一個元件一直向下排列,而不管他們有多寬;而一個設定水平屬性的每一行只有一個元件一直向右排列(高度為最高子元件的高度加上邊框高度)。LinearLayout保持子元件之間的間隔以及互相對齊。
|
屬性名稱
|
描述
|
|
LinearLayout佈局的方向,可取horizontal(水平)和vertical(垂直)兩種排列方式
|
|
|
內部元件對於父元件的對齊方式
|
|
|
元件的分配大小的權值,數字越大分配越多
|
|
<LinearLayout 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="#ff0"
android:orientation="vertical" >
<Button
android:id="@+id/Button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="靠左" />
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="離左邊界30dp" />
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="靠右" />
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="置中" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#cc0"
android:orientation="horizontal" >
<Button
android:id="@+id/Button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/Button11"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:text="以我為列高" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#f0f"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/Button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/Button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
![[Android UI 設計] 版面布局Layout-LinearLayout [Android UI 設計] 版面布局Layout-LinearLayout](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNhyphenhyphenAq9drq1wpSywXKB9GDzoKJxp40ueYyjaH7S00JhyDZH9ma1qjN5gfBV-lvz62FoYV95U9xBkD1CayVA0CUxKO9Q7WKXnSI369dlcnTe68x7zJXb63sJCgBIkFLmzuCZRmsZaukk9A/s1600/Snap5.png)
沒有留言 :
張貼留言