Android ApiDemos示例解析(141):Views->Layouts->LinearLayout->1. Vertical

来源:互联网 发布:推广软件 编辑:程序博客网 时间:2024/04/29 04:52

LinearLayout 将其子View顺序排成一行或是一列,一个垂直列表每行将只有一个子元素(无论它们有多宽),一个水平列表只是一列的高度(最高子元素的高度来填充)。

本例介绍了LinearLayout 的基本用法,LinearLayout的方向可以使用android:orientation 来定义,可以指定vertical 或是 horizontal ,缺省为横向horizontal。

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:background=”@drawable/blue”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>

<!– view1 goes on top –>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_1_top”/>

<!– view2 goes in the middle –>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_1_middle”/>

<!– view3 goes on the bottom –>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_1_bottom”/>

</LinearLayout>