android常用布局

布局

    组件按照布局的要求依次排列,就组成了用户所看见的界面。Android的五大布局分别是LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局)和TableLayout(表格布局)。

一、LinearLayout(线性布局)、FrameLayout(单帧布局)

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 >
7 <!--
8 首先是线性布局这里面每一个元素跟在另一个元素的后面。可参考下列设置!主要是android:layout_weight="1"管用了
9 -->
10 <LinearLayout
11 android:orientation="horizontal"
12 android:layout_width="fill_parent"
13 android:layout_height="wrap_content"
14 >
15 <TextView
16 android:layout_width="fill_parent"
17 android:layout_height="wrap_content"
18 android:layout_weight="1"
19 android:background="#EFDAB8"
20 />
21 <TextView
22 android:layout_width="fill_parent"
23 android:layout_height="wrap_content"
24 android:layout_weight="1"
25 android:background="#FBAFF5"
26 />
27 </LinearLayout>
28 <LinearLayout
29 android:orientation="horizontal"
30 android:layout_width="fill_parent"
31 android:layout_height="wrap_content"
32 >
33 <TextView
34 android:layout_width="fill_parent"
35 android:layout_height="wrap_content"
36 android:layout_weight="2"
37 android:background="#EFDAB8"
38 />
39 <TextView
40 android:layout_width="fill_parent"
41 android:layout_height="wrap_content"
42 android:layout_weight="1"
43 android:background="#FBAFF5"
44 />
45 </LinearLayout>
46 <!--
47 FrameLayout布局就是单帧布局 FrameLayout是五大布局中最简单的一个布局,
48 在这个布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置
49 的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元
50 素之上,将前面的子元素部分和全部遮挡。例子如下
51 -->
52 <FrameLayout
53 android:layout_width="fill_parent"
54 android:layout_height="fill_parent"
55 android:background="#525252"
56 >
57 <TextView
58 android:layout_width="fill_parent"
59 android:layout_height="fill_parent"
60 android:background="#644121"
61 />
62 <TextView
63 android:layout_width="wrap_content"
64 android:layout_height="wrap_content"
65 android:background="#B5D556"
66 android:text="你好我的世界!"
67 android:textSize="24sp"
68 android:textColor="#F56700"
69 />
70 </FrameLayout>
71 </LinearLayout>


原文地址:https://www.cnblogs.com/Acmen/p/2174626.html