android开发布局五_帧布局(FrameLayout)

今天看看五大布局中的最后一个,帧布局(FrameLayout),他是直接继承了ViewGroup组件。

   帧布局容器为每个加入其中的组件创建一个空白的区域(称为一帧),所有每个子组件占据一帧,这些帧都会根据Gravity属性执行自动对其,也就是说帧布局的效果有点类似于awt编程中的CardLayout,都是把组件一个个的叠加在一起,

属性以及方法如下:

XML属性                               相关方法                                      说明

1.android:foregroud          setForegroud(Drawable)              设置该帧布局容器的前景图像

2.android:forgroudGravity   setForegroudGravity(int)    定义绘制前景图像的gravity属性

 

下面写一个例子,程序看到7个TextView叠加在一起,上面的TextView遮住了下面的TextView,代码如下:

ContractedBlock.gif ExpandedBlockStart.gif View Code
 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。

 


 

转载于:https://www.cnblogs.com/bokun-wang/archive/2011/09/29/2195458.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值