使用了LinearLayout布局的组件,会按照水平或者垂直一行(或者一列)只能放置一个组件,嵌套使用可以实现相对复杂的布局。
demon代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:orientation="horizontal" >
<TextView
android:text="@string/color_green"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:background="#90EE90"
android:layout_weight="2"
android:layout_marginRight="5dip"
/>
<TextView
android:text="@string/color_blue"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:background="#836FFF"
android:layout_weight="2"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dip"
android:layout_weight="1.5"
android:orientation="vertical" >
<TextView
android:layout_weight="3"
android:text="@string/color_black"
android:background="#0D0D0D"
android:layout_height="fill_parent"
android:layout_width="match_parent"
/>
<TextView
android:layout_weight="3"
android:text="@string/color_yellow"
android:background="#EEEE00"
android:layout_height="fill_parent"
android:layout_width="match_parent"
/>
<TextView
android:layout_weight="3"
android:text="@string/color_unknown"
android:background="#464868"
android:layout_height="fill_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:text="@string/color_red"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#EE0000"
android:layout_weight="3"
/>
<TextView
android:layout_weight="3"
android:text="@string/color_white"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
效果图: