查看: 1996|回复: 0

[安卓技术] 框架布局FrameLayOut的使用

[复制链接]
  • TA的每日心情

    2014-4-10 13:56
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2014-1-22 13:33:37 | 显示全部楼层 |阅读模式
    分享到:
    框架布局FrameLayOut的使用
            框架布局是android中最简单的一个布局方式,所有添加到这个布局中的视图都是以层叠的方式显示的。也就是说第一个添加到框架布局中的视图显示在最底层,而最后一个视图显示在最上层,上一层的视图会覆盖下一层的视图,它有点类似于堆栈布局(先进后出)。
            它有以下几个属性值:
    属性值                                描述
    Top                                    将视图放到屏幕的顶端
    Buttom                                将视图放到屏幕的底端
    Left                                    将视图放到屏幕的左侧
    Right                                将视图放到屏幕的右侧
    Center_vertical                将视图放到屏幕的垂直居中
    Center_horizontal                将视图放到屏幕的水平居中
    下面就同一个小的列子来介绍一下这个布局方式的使用;
    首先需要建立一个工程:相信都比较熟悉了,再次不多作介绍。
    工程建立好之后,打开布局文件:下图是默认的一个布局文件。
    图片1.png
    对这个布局文件进行修改:
    <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>
    然后运行:可以看出后添加的视图位于之前视图的上层。
    图片2.png

    回复

    使用道具 举报

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

    本版积分规则

    关闭

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



    手机版|小黑屋|与非网

    GMT+8, 2024-5-16 08:25 , Processed in 0.117613 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.