Android 布局之FrameLayout
Android 布局之FrameLayout
1 FrameLayout简介
对于FrameLayout,官方介绍是:
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.
即,设计FrameLayout是为了显示单一项widget。通常,不建议使用FrameLayout显示多项内容;因为它们的布局很难调节。不用layout_gravity属性的话,多项内容会重叠;使用layout_gravity的话,能设置不同的位置。layout_gravity可以使用如下取值:
top
将对象放在其容器的顶部,不改变其大小.
bottom
将对象放在其容器的底部,不改变其大小.
left
将对象放在其容器的左侧,不改变其大小.
right
将对象放在其容器的右侧,不改变其大小.
center_vertical
将对象纵向居中,不改变其大小.
垂直对齐方式:垂直方向上居中对齐。
fill_vertical
必要的时候增加对象的纵向大小,以完全充满其容器.
垂直方向填充
center_horizontal
将对象横向居中,不改变其大小.
水平对齐方式:水平方向上居中对齐
fill_horizontal
必要的时候增加对象的横向大小,以完全充满其容器.
水平方向填充
center
将对象横纵居中,不改变其大小.
fill
必要的时候增加对象的横纵向大小,以完全充满其容器.
clip_vertical
附加选项,用于按照容器的边来剪切对象的顶部和/或底部的内容. 剪切基于其纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部.
垂直方向裁剪
clip_horizontal
附加选项,用于按照容器的边来剪切对象的左侧和/或右侧的内容. 剪切基于其横向对齐设置:左侧对齐时,剪切右侧;右侧对齐时剪切左侧;除此之外剪切左侧和右侧.
水平方向裁剪
注意: 区分“android:gravity”和“android:layout_gravity”。
android:gravity :是对控件本身来说的,是用来设置“控件自身的内容”应该显示在“控件自身体积”的什么位置,默认值是左侧。
android:layout_gravity:是相对于控件的父元素来说的,设置该控件在它的父元素的什么位置。
2 FrameLayout示例
创建一个activity,包含2组FrameLayout:1组设置android:layout_gravity属性,另1组不设置android:layout_gravity属性。
layout文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <!-- 示例1 FrameLayout内容重叠 -->
<TextView
android:text="示例1, FrameLayout内容重叠"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="300dp"
android:layout_height="80dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是TextView,内容比较长"
android:background="#ff0000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:text="我是按钮"/> </FrameLayout> <!-- 示例2 FrameLayout使用layout_gravity属性 -->
<TextView
android:text="示例2, 设置layout_gravity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="300dp"
android:layout_height="120dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本居左"
android:background="#ff0000"
android:gravity="center"
android:layout_gravity="left"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本居中"
android:background="#ffff00"
android:gravity="center"
android:layout_gravity="center"/>
</FrameLayout>
</LinearLayout>
点击下载:源代码
运行效果:如图

Android 布局之FrameLayout的更多相关文章
- Android布局之FrameLayout
框架布局(帧布局)是最简单的布局形式.所有添加到这个布局中的视图都以层叠的方式显示.第一个添加的控件被放在最底层,最后一个添加到框架布局中的视图显示在最顶层,上一层的控件会覆盖下一层的控件.这种显示方 ...
- Android布局及属性归总(查询用)
常见布局 LinearLayout 线性布局 子元素任意,组织成一个单一的水平或垂直行,默认为水平方向TableLayout 表格布局 子元素为<Tabl ...
- android布局学习-使用FrameLayout和LinearLayout制作QQ空间底部导航栏
[声明:本博客通过学习“J灬叶小超 ”博客而写,链接:http://www.cnblogs.com/yc-755909659/p/4288260.html] --------------------- ...
- android布局 FrameLayout(帧布局)详解
看到一篇很有趣的文章对我就是冲着萌妹子看的 FrameLayout(帧布局) 前言 作为android六大布局中最为简单的布局之一,该布局直接在屏幕上开辟出了一块空白区域, 当我们往里面添加组件的时候 ...
- Android布局_帧布局FrameLayout
一.FrameLayout布局概述 在这个布局中,所有的子元素都不能被指定放置的位置,他们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡 如下面的 ...
- Android布局详解之一:FrameLayout
原创文章,如有转载,请注明出处:http://blog.csdn.net/yihui823/article/details/6702273 FrameLayout是最简单的布局了.所有放在布局里的 ...
- Android(java)学习笔记93:Android布局详解之一:FrameLayout
FrameLayout是最简单的布局了.所有放在布局里的控件,都按照层次堆叠在屏幕的左上角.后加进来的控件覆盖前面的控件. 在FrameLayout布局里,定义任何空间的位置相关的属性都毫无意义.控件 ...
- Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)
首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...
- Android中的FrameLayout帧布局
帧布局由FrameLayout所代表,FrameLayout直接继承了ViewGoup组件. 帧布局容器为每一个增加当中的组件创建一个空白的区域(称为一个帧),每一个子组件占领一帧,这些帧都会依据gr ...
随机推荐
- 关闭Windows Update更新驱动程序
关于Win10的更新配置,特别是自动更新驱动程序,经常会导致驱动安装错误而无法开机的问题. 此时只好开机时按F8进入高级模式恢复最后一次正确配置,或者在安全模式删除错误的驱动程序. 关于Win10的更 ...
- spark spark ziliao important
http://book.51cto.com/art/201408/448416.htm 一.如何实现多台机器的ssh无密码登录 当我们在配置多台计算,使之可以相互使用无密码登录-ssh,之前都是一台一 ...
- 销傲销售过程GSP管理系统功能概述
1 公司介绍 西安海思威软件有限公司于2009年2月注册成立,海思威软件公司隶属于海思威集团,位于交通十分便利的西安经济技术开发区.公司致力于中国本土式销售管理的研究与管理软件产品的开发,是 ...
- iOS设备类型
通常App都会采集用户的设备信息,比如设备类型.网络类型.内存大小等,而拿到的数据比如:iPhone 8,1是什么意思?代表iOS 8.1吗,非也.这里放二个网站大家可以上去查一查,在统计分析的系统里 ...
- CAN Timing Sample Point
typedef struct { //char name[ 16 ]; // Name of the CAN controller hardware //uint32_t ref_clk; // CA ...
- Eclipse 基于接口编程的时候,快速跳转到实现类的方法(图文)
Eclipse 基于接口编程的时候,要跳转到实现类很麻烦,其实Eclipse已经实现该功能. 只要按照Ctrl键,把鼠标的光标放在要跳转的方法上面,第一个是跳转到接口里面,第二个方法是跳转到实现类的位 ...
- 和View Controllers一起工作
在这一课中,你会继续在FoodTracker菜谱的场景工作.你会重新安排现有的UI元素并使用图像采集器添加到照片用户界面.当你完成,你的应用程序将是这个样子: 学习目标 在课程结束时,你将能够: 了解 ...
- Solved: Qt Library LNK 2001 staticMetaObject error
在链接Qt的库,比如QtGui4.lib,我这里是在链接QtSolutions_PropertyBrowser-head.lib的时候出现的链接错误.大概是说一个"XXXX::s ...
- C#标准响应数据
public HttpResponseMessage UpdateModule(Mode mode) { var response = Process.Instance.ExecuteString(( ...
- aspcms常见问题解决方案
1.产品详细页读取多张产品图片(栏目类型:产品){aspcms:cimages count=16 contentid=[content:id]}<li onmouseover="sho ...