Android五种布局管理器之『FrameLayout』

帧布局(FrameLayout)在屏幕上开辟了一块区域,在这块区域中可以添加多个子控件,但是所有的子控件都会被对齐到屏幕的左上角。帧布局的大小由其下属子控件中尺寸最大的那个子控件来控制。如果子控件的大小都一样,同一时刻只能看到最上面的子控件,其他的则被其遮挡(在进行选项卡设计时会用到帧布局)。

FrameLayout继承自ViewGroup类,除了继承自父类的属性和方法,FrameLayout类中也包含了自己特有的一些属性和方法,见下表:

属性名称 对应方法 描述
android:foregroundsetForeground(Drawable)设置绘制在所有子控件之上的内容
android:foregroundGravitysetForegroundGravity(int)设置绘制在所有子控件之上内容的gravity属性

提示:在FrameLayout中,子控件是通过栈来绘制的,所以后添加的子控件会被绘制在上层。

下面就来看一个帧布局的例子效果图:

点击放大图片

其中Main.xml代码如下:

 
 
 
 
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <FrameLayout  
  3.       android:id="@+id/FrameLayout01"  
  4.       android:layout_width="fill_parent"  
  5.       android:layout_height="fill_parent"  
  6.       android:background="#FFFFFF" 
  7.       xmlns:android="http://schemas.android.com/apk/res/android"> 
  8.        
  9.       <TextView  
  10.           android:text="大字体"  
  11.           android:id="@+id/TextView01"  
  12.           android:layout_width="wrap_content"  
  13.           android:layout_height="wrap_content" 
  14.           android:textSize="60px" 
  15.           android:textColor="#00FF00" 
  16.       > 
  17.       </TextView> 
  18.       <TextView  
  19.           android:text="中字体"  
  20.           android:id="@+id/TextView02"  
  21.           android:layout_width="wrap_content"  
  22.           android:layout_height="wrap_content" 
  23.           android:textSize="40px" 
  24.           android:textColor="#FF0000" 
  25.       > 
  26.       </TextView> 
  27.       <TextView  
  28.           android:text="小字体"  
  29.           android:id="@+id/TextView03"  
  30.           android:layout_width="wrap_content"  
  31.           android:layout_height="wrap_content" 
  32.           android:textSize="20px" 
  33.           android:textColor="#0000FF" 
  34.       > 
  35.       </TextView> 
  36. </FrameLayout> 

Activity代码为:

 
 
 
 
  1. package com.sunchis; 
  2.  
  3. import android.app.Activity; 
  4. import android.os.Bundle; 
  5.  
  6. public class Android extends Activity {  
  7.     @Override 
  8.     public void onCreate(Bundle savedInstanceState) { 
  9.         super.onCreate(savedInstanceState); 
  10.         setContentView(R.layout.main);          //设置屏幕 
  11.     } 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值