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:src="@drawable/droid" > </ImageView> </FrameLayout> </RelativeLayout>
这里,在RelativeLayout中内嵌了一个FrameLayuout,在FrameLayuout 中内嵌了一个ImageView。效果图:
开发入门(五)屏幕组件 5.6 FrameLayout帧布局-unity layout 组件">
但是,如果想要在这个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:src="@drawable/droid" > </ImageView> <Button android:layout_width="124dp" android:layout_height="wrap_content" android:text="Print Picture" /> </FrameLayout> </RelativeLayout>
最终效果图:
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索布局
, view
, imageview
, 视图
, relativelayout
, 添加头布局 android
, 帧布局
, framelayout
, 一个
, Android添加组件
, 帧布局frameLayout
framelayout布局
unity layout 组件、layout组件、ireport frame组件、framelayout、android framelayout,以便于您获取更多的相关知识。