基本屬性要求

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 </LinearLayout>

排列方向

  • android:orientation
    1. 決定LinearLayout內部元件會以水平或是垂直排列。
    2. 如果沒有設定此屬性,LinearLayout預設會使用水平排列。
    3. vertical 垂直排列。
    4. horizontal 水平排列。

範例:垂直排列Button

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2" />

</LinearLayout>

範例:水平排列Button

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2" />

</LinearLayout>