回答

收藏

[求助] 框架布局FrameLayOut的使用

飞凌嵌入式 飞凌嵌入式 2975 人阅读 | 0 人回复 | 2014-01-23

本帖最后由 forlinx2013 于 2014-1-24 09:27 编辑

欢迎大家来到飞凌爱板网专区,对嵌入式技术感兴趣的朋友不妨多多关注一下,我们提供了公司所有开发板的所有资料,也会更新大量技术文章,欢迎大家一块学习提高!!!

框架布局FrameLayOut的使用
        框架布局是android中最简单的一个布局方式,所有添加到这个布局中的视图都是以层叠的方式显示的。也就是说第一个添加到框架布局中的视图显示在最底层,而最后一个视图显示在最上层,上一层的视图会覆盖下一层的视图,它有点类似于堆栈布局(先进后出)。
        它有以下几个属性值:
属性值                                描述
Top                                    将视图放到屏幕的顶端
Buttom                                将视图放到屏幕的底端
Left                                    将视图放到屏幕的左侧
Right                                将视图放到屏幕的右侧
Center_vertical                将视图放到屏幕的垂直居中
Center_horizontal                将视图放到屏幕的水平居中

下面就同一个小的列子来介绍一下这个布局方式的使用;
首先需要建立一个工程:相信都比较熟悉了,再次不多作介绍。
工程建立好之后,打开布局文件:下图是默认的一个布局文件。
对这个布局文件进行修改:
<FrameLayout         xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
<ImageButton
            android:id="@+id/image01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/beijing"
            android:layout_gravity="center"
            />
<ImageButton
            android:id="@+id/image02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:layout_gravity="center"(中间)
            />
<ImageButton
            android:id="@+id/image03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:layout_gravity="top|center_horizontal"(顶上水平居中)
            />
<ImageButton
            android:id="@+id/image04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:layout_gravity="bottom|center_horizontal"(底层水平居中)
            />
</FrameLayout>
然后运行:可以看出后添加的视图位于之前视图的上层。

分享到:
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条