实验1-线性,相对,表格布局
表格布局
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="2">
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="按钮1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="按钮2"/>
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="按钮3"/>
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="按钮4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="按钮5"/>
</TableRow>
</TableLayout>
相对布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_one"
android:layout_width="168dp"
android:layout_height="170dp"
android:text="按钮1"
android:layout_alignParentTop="true"/>
<Button
android:id="@+id/btn_two"
android:layout_width="168dp"
android:layout_height="170dp"
android:text="按钮2"
android:layout_alignParentRight="true"/>
<Button
android:id="@+id/btn_three"
android:layout_width="168dp"
android:layout_height="170dp"
android:text="按钮3"
android:layout_centerInParent="true"
android:layout_marginTop="100dp"/>
<Button
android:id="@+id/btn_four"
android:layout_width="168dp"
android:layout_height="170dp"
android:text="按钮4"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<Button
android:id="@+id/btn_five"
android:layout_width="168dp"
android:layout_height="170dp"
android:text="按钮5"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>