灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2989回复:0

Android 程式开发:(五)屏幕组件 —— 5.6 FrameLayout帧布局

楼主#
更多 发布于:2012-09-06 14:04


FrameLayout就是屏幕上的一个“定位器”,可以使用它去显示一个单一的视图。被添加到FrameLayout上的视图views总是被固定在这个布局的左上角。考虑以下的代码:



<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"  
    Android:id="@+id/RLayout"  
    Android:layout_width="fill_parent"  
    Android:layout_height="fill_parent" >  
  
    <TextView  
        Android:id="@+id/lblComments"  
        Android:layout_width="wrap_content"  
        Android:layout_height="wrap_content"  
        Android:layout_alignParentLeft="true"  
        Android:layout_alignParentTop="true"  
        Android:text="Hello, Android!" />  
  
    <FrameLayout  
        Android:layout_width="wrap_content"  
        Android:layout_height="wrap_content"  
        Android:layout_alignLeft="@+id/lblComments"  
        Android:layout_below="@+id/lblComments"  
        Android:layout_centerHorizontal="true" >  
  
        <ImageView  
            Android:layout_width="wrap_content"  
            Android:layout_height="wrap_content"  
            Android[/img]
但是,如果想要在这个FrameLayuout中添加另外的view(比如一个Button),那么这个view就会重叠在“之前的”view上面(本例中是显示图片的ImageView)。代码:



<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"  
    Android:id="@+id/RLayout"  
    Android:layout_width="fill_parent"  
    Android:layout_height="fill_parent" >  
  
    <TextView  
        Android:id="@+id/lblComments"  
        Android:layout_width="wrap_content"  
        Android:layout_height="wrap_content"  
        Android:layout_alignParentLeft="true"  
        Android:layout_alignParentTop="true"  
        Android:text="Hello, Android!" />  
  
    <FrameLayout  
        Android:layout_width="wrap_content"  
        Android:layout_height="wrap_content"  
        Android:layout_alignLeft="@+id/lblComments"  
        Android:layout_below="@+id/lblComments"  
        Android:layout_centerHorizontal="true" >  
  
        <ImageView  
            Android:layout_width="wrap_content"  
            Android:layout_height="wrap_content"  
            Android[/img]
摘自 manoel的专栏

喜欢0 评分0
游客

返回顶部