线性布局LinearLayout
一、简介
LinearLayout是一种线型的布局方式。LinearLayout布局容器内的组件一个挨着一个地排列起来:不仅可以控制个组件横向排列,也可控制各组件纵向排列。通过orientation属性设置线性排列的方向是垂直(vertical)还是纵向(horizontal)。
线性布局实例
二、代码实例
效果图:
结构
代码:
/Test_LinearLayout/res/layout/activity_main.xml
android:layout_weight="4"
权重
android:gravity="bottom|right"
字体靠右下
android:orientation="vertical" >
垂直布局
xmlns:android="http://schemas.android.com/apk/res/android"
命名空间
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 <!-- 输入框 -->
7 <EditText
8 android:id="@+id/editText_input"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:gravity="bottom|right"
12
13 android:text=""
14 android:layout_weight="4"
15 android:textSize="@dimen/fontSize_num"
16 />
17
18 <!-- 中间按键区 -->
19 <LinearLayout
20 android:layout_width="match_parent"
21 android:layout_height="wrap_content"
22 android:orientation="vertical"
23 android:layout_weight="12"
24
25 >
26 <!-- 中间按键区:第一排 -->
27 <LinearLayout
28 android:layout_width="match_parent"
29 android:layout_height="wrap_content"
30 android:orientation="horizontal"
31 android:layout_weight="1"
32
33 >
34 <Button
35 android:id="@+id/btn_num7"
36 android:layout_width="wrap_content"
37 android:layout_height="wrap_content"
38 android:text="7"
39 android:layout_weight="2"
40 android:textSize="@dimen/fontSize_num"
41 />
42 <Button
43 android:id="@+id/btn_num8"
44 android:layout_width="wrap_content"
45 android:layout_height="wrap_content"
46 android:text="8"
47 android:layout_weight="2"
48 android:textSize="@dimen/fontSize_num"
49 />
50 <Button
51 android:id="@+id/btn_num9"
52 android:layout_width="wrap_content"
53 android:layout_height="wrap_content"
54 android:text="9"
55 android:layout_weight="2"
56 android:textSize="@dimen/fontSize_num"
57 />
58 <Button
59 android:id="@+id/btn_symbol_divide"
60 android:layout_width="wrap_content"
61 android:layout_height="wrap_content"
62 android:text="/"
63 android:layout_weight="2"
64 android:textSize="@dimen/fontSize_num"
65 />
66 </LinearLayout>
67
68 <!-- 中间按键区:第二排 -->
69 <LinearLayout
70 android:layout_width="match_parent"
71 android:layout_height="wrap_content"
72 android:orientation="horizontal"
73 android:layout_weight="1"
74 android:textSize="@dimen/fontSize_num"
75 >
76 <