本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/
FrameLayout就是屏幕上的一个“定位器”,可以使用它去显示一个单一的视图。被添加到FrameLayout上的视图views总是被固定在这个布局的左上角。考虑以下的代码:
- <?xmlversion="1.0"encoding="utf-8"?>
- <RelativeLayoutxmlns: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:src="@drawable/droid">
- </ImageView>
- </FrameLayout>
- </RelativeLayout>
这里,在RelativeLayout中内嵌了一个FrameLayuout,在FrameLayuout中内嵌了一个ImageView。效果图:
但是,如果想要在这个FrameLayuout中添加另外的view(比如一个Button),那么这个view就会重叠在“之前的”view上面(本例中是显示图片的ImageView)。代码:
- <?xmlversion="1.0"encoding="utf-8"?>
- <RelativeLayoutxmlns: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:src="@drawable/droid">
- </ImageView>
- <Button
- android:layout_width="124dp"
- android:layout_height="wrap_content"
- android:text="PrintPicture"/>
- </FrameLayout>
- </RelativeLayout>
最终效果图:
分享到:
相关推荐
主要介绍了Android布局之FrameLayout帧布局的相关资料,需要的朋友可以参考下
Android中帧布局FrameLayout的特点.pdf 学习资料 复习资料 教学资源
Android中帧布局FrameLayout的常用属性.pdf 学习资料 复习资料 教学资源
FrameLayout(帧布局)实现闪烁霓虹灯效果
使用安卓手机帧布局实现多个布局或控件的重叠!
Android中使用FrameLayout布局完成教学案例的代码清单.pdf 学习资料 复习资料 教学资源
Android中使用FrameLayout布局完成教学案例的要求说明.pdf 学习资料 复习资料 教学资源
高仿新浪微博,采用FrameLayout布局的形式来实现下拉刷新。 在原程序的基础上添加了下拉刷新后listview列表内容的更新,更好的模拟刷新后的效果。 程序已在模拟器中测试通过,且效果很好。
FrameLayout 帧布局、框架布局 创建一个空白区域, 一个区域成为一帧 TableLayout 表格布局 采用 行, 列 形式管理子组件,添加TableRow 和 组件 就可以控制表格的行数和列数 GridLayout 网格布局 设置行列来装填控件 ...
Android Framelayout显示静态和动态的扑克牌 包含Handler 和Timer TimerTask的使用方法
使用FrameLayout帧布局实现tabhost的效果
主要为大家详细介绍了Android布局之帧布局FrameLayout,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
android demo,FrameLayout的使用,该实例实现了一个美女在地图上的行走。
文档介绍了前言,FrameLayout布局,LinearLayout布局,RelativeLayout布局,TableLayout布局,AbsoluteLayout布局
本文实例讲述了Android开发实现布局帧布局霓虹灯效果。分享给大家供大家参考,具体如下: 效果图: 实现方式: FrameLayout中,设置8个TextView,在主函数中,设计颜色数组,通过有序替换他们颜色,实现渐变效果。 ...
帧布局(FrameLayout):组件从屏幕左上方布局组件。 表格布局(TableLayout):按照行列方式布局组件。 相对布局(RelativeLayout):相对其它组件的布局方式。 绝对布局(AbsoluteLayout):按照绝对坐标来布局...
智能家居系统 帧布局FrameLayout.doc 学习资料 复习资料 教学资源
该资源与文章http://blog.csdn.net/nianhua120/article/details/51387668 相配套。详细请参考该文章。