绝对布局
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="40dp"
android:layout_y="20dp"
android:text="测试文字" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="183dp"
android:layout_y="65dp"
android:text="Button" />
<!-- 评分条星星 -->
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="-26dp"
android:layout_y="52dp" />
<!-- 时钟 -->
<AnalogClock
android:id="@+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="41dp"
android:layout_y="102dp" />
</AbsoluteLayout>
帧布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/azure"
android:layout_gravity="center"
/>
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@color/blanchedalmond"
android:layout_gravity="center"
/>
</FrameLayout>
网格布局
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="4"
>
<!-- 网格布局,确保版本在4.0以上,如果低于4.0,则需要导入一个支持包 -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_rowSpan="2"
android:layout_gravity="fill_vertical"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
/>
</GridLayout>
线性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center"
android:orientation="vertical">
<!-- 权重 layout_weight -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本1"
android:background="@color/bisque"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本2"
android:background="@color/blueviolet"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本3"
android:background="@color/teal"/>
</LinearLayout>
相对布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:text="按钮1" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:text="按钮2" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:layout_alignParentRight="true"
android:text="按钮3" />
<TextView
android:id="@+id/tv_main_four"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:text="按钮4" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:layout_toLeftOf="@id/tv_main_four"
android:layout_alignBottom="@id/tv_main_four"
android:text="按钮5" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:layout_toRightOf="@id/tv_main_four"
android:layout_centerVertical="true"
android:text="按钮6" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textSize="15sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:text="按钮7" />
</RelativeLayout>
表格布局
<?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" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="表1" />
<!--
android:shrinkColumns="1"某列可收缩
android:stretchColumns="0"某列可伸展
-->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="0" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<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
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我向横方向伸展,我可以很长" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我向列方向收缩,我可以很深" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="表2" />
<TableLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第0列" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第1列" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第2列" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="我被制定在第一列" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:background="#ff0000"
android:text="跨1.。。。。。。2"
android:layout_span="2"
/>
</TableRow>
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="表3不均匀" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<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>
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="表4均匀" />
<TableLayout
android:stretchColumns="*"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="一"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="量子"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="三个字"
/>
</TableRow>
</TableLayout>
</LinearLayout>
RTL布局
<?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"
android:layoutDirection="rtl"
>
<!-- 从右到左布局(适用安卓4.0以上的版本)-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本1"
android:background="#ff0000"
android:textSize="30sp"
android:textColor="#ffffff"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本2"
android:background="#00ff00"
android:textSize="30sp"
android:textColor="#ffffff"
android:layout_marginStart="20dp"
/>
<!-- 布局的重用 -->
<include
layout="@layout/activity_tablelayout"
/>
</LinearLayout>