2.android中常见布局
[1]线性布局 水平 垂直.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<!--@符合就代表R文件-->
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入手机号:"
android:textSize="25sp"
/>
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨打此号码"
/>
</LinearLayout>
[2]相对布局 里面的控件默认都从左上角开始排列
<?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">
<!--快速格式化代码 ctrl + alt + l-->
<!--@符合就代表R文件-->
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入手机号:"
android:textSize="25sp" />
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_number"
android:hint="请输入手机号"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et_number"
android:text="拨打此号码"
/>
</RelativeLayout>
[3]帧布局 分层展示控件.
<?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">
<!--@符合就代表R文件-->
<TextView
android:id="@+id/tv_number"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="这是视频播放的内容:"
android:textSize="25sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨打"
android:layout_gravity="center"
/>
</FrameLayout>
[4]表格布局 表格由行和列构成
<?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">
<!--一个tablerow就代表一行 具体的控件表示列-->
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1111" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2222" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1111" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2222" />
</TableRow>
</TableLayout>
[5]绝对布局 已经过时 我们开发中很少用
[6]总结:实际开发中我们使用线性布局和相对布局组合.