The following example is used to illustrate the nested use of window layout.
Note: Each layout and control must specify at least its width and height. The use of nesting is flexible and can be nested and nested.
Linearlayout and tablelayout are nested in each other to implement a more complex layout. Pay attention to the parallelism of various layout relationships and set weights.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical"> <LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"> <TextView android:text="red" android:background="#aa0000" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1"/> <TextView android:text="green" android:background="#00aa00" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1"/> <TextView android:text="blue" android:background="#0000aa" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1"/> <TextView android:text="yellow" android:background="#aaaa00" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"> <TextView android:text="firstRow" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#00aaaa"/> <TextView android:text="secondRow" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#aa00aa"/> <TextView android:text="thirdRow" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#0000aa"/> </LinearLayout></LinearLayout>
Result