LinearLayout

<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
> <LinearLayout android:layout_width="100dp" android:layout_height="100dp" android:background="#ff0000" /> <LinearLayout android:layout_width="100dp" android:layout_height="100dp" android:background="#00ff00" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#ffffff"/> <LinearLayout android:layout_width="100dp" android:layout_height="100dp" android:background="#0000ff" />
</LinearLayout>
|
RelativeLayout


<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout android:layout_width="100dp" android:layout_height="100dp" android:background="#ff0000" android:layout_alignParentRight="true" android:id="@+id/rl1" />
<RelativeLayout android:layout_width="100dp" android:layout_height="100dp" android:background="#00ff00" android:layout_marginLeft="100dp" />
</RelativeLayout>
|
FrameLayout

<?xml version="1.0" encoding="utf-8"?> <FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <FrameLayout android:layout_width="400dp" android:layout_height="400dp" android:background="#ff0000"/> <FrameLayout android:layout_width="300dp" android:layout_height="300dp" android:foreground="@drawable/ic_launcher_background" android:foregroundGravity="right|bottom" android:background="#00ff00"/> <FrameLayout android:layout_width="200dp" android:layout_height="200dp" android:background="#0000ff"/>
</FrameLayout>
|
TableLayout

注意:要有空间剩余时拉伸才有效,有控件超出空间时,收缩才有效。
<?xml version="1.0" encoding="utf-8"?> <TableLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:collapseColumns="0" android:stretchColumns="1" android:shrinkColumns="3" > <TableRow> <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="第二个" />
<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="第四个" /> </TableRow>
<TableRow> <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="第二个" />
<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="第四个" /> </TableRow>
<TableRow> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一个" android:layout_column="1" />
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二个" android:layout_span="23"/> </TableRow> </TableLayout>
|
GridLayout


<?xml version="1.0" encoding="utf-8"?> <GridLayout android:layout_height="wrap_content" android:layout_width="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal">
<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:layout_row="2" android:layout_column="2" android:layout_columnWeight="1" android:text="第二个"/>
<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="第四个"/> </GridLayout>
|
ConstrainLayout
直接在Design界面进行操作就行了