【Android(安卓)开发教程】FrameLayout帧布局
16lz
2021-01-25
本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/FrameLayout就是屏幕上的一个“定位器”,可以使用它去显示一个单一的视图。被添加到FrameLayout上的视图views总是被固定在这个布局的左上角。考虑以下的代码:
[html] view plain copy- <?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>
但是,如果想要在这个FrameLayuout中添加另外的view(比如一个Button),那么这个view就会重叠在“之前的”view上面(本例中是显示图片的ImageView)。代码:
[html] view plain copy- <?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>
更多相关文章
- 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
- Android系统源代码目录与系统目录
- mtk android SD 配置 (MT6572)
- Android(安卓)Handler机制4--MessageQueue简介
- Android(安卓)工具类 —— 判断网络连接状态、GPS是否打开、基站
- Android自带的几种Activirty
- 网页中android Toast效果的实现
- Android(安卓)学习笔记 databinding简单使用:使用databinding在li
- android与phonegap的相互交互