android Layout之FrameLayout

 

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

示例代码如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text = "short text"/>
<TextView android:id="@+id/text2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor = "#0000FF"
    android:textSize="40px"
    android:text = "This is a long text ,long text"/>
</FrameLayout>

结果显示如下:

 

FrameLayout继承ViewGroup类,除了继承父类的属性和方法外,FrameLayout类中还包含了自己特有属性和方法:

android:foreground setForeground(Drawable))设置绘制在所有子控件之上的内容

android:foregroundGravitysetForegroundGravity(int))设置绘制在所有子控件之上内容的gravity属性

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值