android开发布局五_帧布局(FrameLayout)
今天看看五大布局中的最后一个,帧布局(FrameLayout),他是直接继承了ViewGroup组件。
帧布局容器为每个加入其中的组件创建一个空白的区域(称为一帧),所有每个子组件占据一帧,这些帧都会根据Gravity属性执行自动对其,也就是说帧布局的效果有点类似于awt编程中的CardLayout,都是把组件一个个的叠加在一起,
属性以及方法如下:
XML属性 相关方法 说明
1.android:foregroud setForegroud(Drawable) 设置该帧布局容器的前景图像
2.android:forgroudGravity setForegroudGravity(int) 定义绘制前景图像的gravity属性
下面写一个例子,程序看到7个TextView叠加在一起,上面的TextView遮住了下面的TextView,代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="utf-8"?>
2 <FrameLayout 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 <TextView
8 android:id="@+id/textview1"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:width="210px"
12 android:height="50px"
13 android:background="#ff0000"
14 />
15
16 <TextView
17 android:id="@+id/textview2"
18 android:layout_width="wrap_content"
19 android:layout_height="wrap_content"
20 android:width="180px"
21 android:height="50px"
22 android:background="#dd0000"
23 />
24
25 <TextView
26 android:id="@+id/textview3"
27 android:layout_width="wrap_content"
28 android:layout_height="wrap_content"
29 android:width="150px"
30 android:height="50px"
31 android:background="#bb0000"
32 />
33
34 <TextView
35 android:id="@+id/textview4"
36 android:layout_width="wrap_content"
37 android:layout_height="wrap_content"
38 android:width="120px"
39 android:height="50px"
40 android:background="#990000"
41 />
42
43 <TextView
44 android:id="@+id/textview5"
45 android:layout_width="wrap_content"
46 android:layout_height="wrap_content"
47 android:width="90px"
48 android:height="50px"
49 android:background="#770000"
50 />
51
52 <TextView
53 android:id="@+id/textview6"
54 android:layout_width="wrap_content"
55 android:layout_height="wrap_content"
56 android:width="60px"
57 android:height="50px"
58 android:background="#550000"
59 />
60
61 <TextView
62 android:id="@+id/textview7"
63 android:layout_width="wrap_content"
64 android:layout_height="wrap_content"
65 android:width="30px"
66 android:height="50px"
67 android:background="#330000"
68 />
69 </FrameLayout>
运行效果如下:最上面的TextView遮挡住下面的textview。
posted on 2011-09-29 14:08 wangbokun 阅读(6026) 评论(0) 编辑 收藏 举报