安卓开发24:FrameLayout布局

来源:互联网 发布:youtube是什么软件 编辑:程序博客网 时间:2024/06/08 06:05

FrameLayout布局

FrameLayout是五大布局中最简单的一个布局。FrameLayout布局中的元素会根据先后顺序重叠起来。利用FrameLayout布局元素重叠的特性,我们一般可以做一些层的隐藏和显示,以及在一个图片上放置另外一个小图标等这样的功能。


看代码:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <!-- 底图 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical" >        <ImageView            android:id="@+id/imageView1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:gravity="center_horizontal"            android:src="@drawable/test1" />    </LinearLayout>    <!-- 这个视图会覆盖在上面那个图的上方 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical" >        <ImageView            android:id="@+id/imageView2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="100dp"            android:layout_marginTop="100dp"            android:src="@drawable/ic_launcher" />    </LinearLayout>    <!-- 不可见视图 -->    <ImageView        android:id="@+id/imageView3"        android:visibility="gone"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/jhs_button1_h4" /></FrameLayout>

效果:第一张图在最底下,第二张图在上面,第三张图被gone隐藏了。


原创粉丝点击