android的framelayout,Android FrameLayout和使用FrameLayout应该注意的地方

FrameLayout单帧布局,在单帧布局中整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。

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

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

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

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

显示效果:

a4c26d1e5885305701be709a3d33442f.png

XML:

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:textColor="#00aa00"

android:textSize="15dp" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:textColor="#aaaa00"

android:textSize="30dp" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:textColor="#aaaaaa"

android:textSize="45dp" />

注意:在FrameLayout布局里面android:layout_margin的各种属性必须依赖于android:layout_gravity,也就是说,要想margin生效,必须设定view的layout_gravity属性。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值