Five Android layouts

时间:2023-03-08 17:47:03

线性布局:

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6 <!-- 上下左右全部填充100dp最终是已后加载的为准 -->
7 <TextView
8 android:id="@+id/tv_number"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:layout_marginLeft="30dp"
12 android:layout_margin="100dp"
13 android:text="请输入电话号码"/>
14 <EditText
15 android:layout_width="match_parent"
16 android:layout_height="wrap_content"
17 android:hint="请输入电话号码"
18 />
19
20
21 <Button
22 android:layout_width="wrap_content"
23 android:layout_height="wrap_content"
24 android:text="拨打"
25 />
26
27 </LinearLayout>

相对布局:

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 tools:context=".MainActivity" >
6 <!-- 相对布局默认都是从左上角开始布局 -->
7 <TextView 8 android:id="@+id/tv_number"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="请输入电话号码" />
12
13 <EditText
14 android:id="@+id/et_number"
15 android:layout_width="match_parent"
16 android:layout_height="wrap_content"
17 android:hint="请输入电话号码"
18 android:layout_below="@id/tv_number"
19 />
20
21 <Button
22 android:id="@+id/btn_number"
23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:text="拨打"
26 android:layout_below="@id/et_number"
27 />
28
29 <Button
30 android:layout_width="wrap_content"
31 android:layout_height="wrap_content"
32 android:text="按钮"
33 android:layout_toRightOf="@id/btn_number"
34 android:layout_below="@id/et_number"
35 />
36
37
38 </RelativeLayout>