LinearLayout布局其实当我们创建第一个安卓程序的时候就已经看见了,它就在main.xml文件中就已经出现了,那它究竟是什么呢?用简单直译它就是线性布局,它是一个最常见的布局方式,它可以分为水平线性布局和垂直线性布局两种,通过android:orientation属性可以改变布局的方向。其实这个布局说那么多还不如写各程序来看的直接,创建一个安卓程序,写下main.xml里面的代码,其它不用变就可以测试看一下简单的一些例子:
main.xml布局文件内容:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="消失"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="#000fff"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ff0000"/>
</LinearLayout>
</LinearLayout>
虽然不止这些,但也不可能一个小小的例子就可以让我们应用自如,还需要我们多加尝试。