閱讀1012 返回首頁    go 阿裏雲 go 技術社區[雲棲]


7.2 LinearLayout布局詳解

LinearLayout線性布局,線性布局是所有布局中最常用的,它可以讓其中的子元素垂直或水平的方式排列(通過排列方向的設置)。通常複雜的布局都是在LinearLayout布局中嵌套而成的。
下麵看一個LinearLayout的例子,這個例子中有垂直和水平的嵌套使用,例子如下圖7-12所示。
 


圖7-12 LinearLayout
布局文件請參考代碼清單7-14,完整代碼請參考chapter7_2工程中linearlayout2.xml代碼部分(chapter7_2/res/layout/linearlayout2.xml)。
【代碼清單7-14】
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
android:textSize="20dip" android:gravity="center" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/user"
android:textSize="15dip" />
<EditText android: android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/pass"
android:textSize="15dip" />
<EditText android: android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:text="@string/loginbtn" android:
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@string/registerbtn" android:
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

</LinearLayout>

                                                                                        出自《Android開發案例驅動教程》第七章


最後更新:2017-04-02 06:51:45

  上一篇:go 白天謀生存,晚上謀發展
  下一篇:go ECLIPSE DEBUG時怎樣以十六進製的方式查看變量的值?