Android笔记(九) Android中的布局——框架布局
框架布局没有任何定位方式,所有的控件都会摆放在布局的左上角。
代码示例:
framelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstView"
android:text="第一层"
android:textSize="50sp"
android:textColor="#000000"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondView"
android:text="第二层"
android:textSize="30sp"
android:textColor="#ffff00"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thirdView"
android:text="第三层"
android:textSize="15sp"
android:textColor="#ff00ff"/> </FrameLayout>
显示结果为:

由此可见
framelayout布局中的元素都是直接摆放在布局的左上角的
我们稍微对代码做一下修改
framelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstView"
android:text="第一层"
android:textSize="50sp"
android:textColor="#000000"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondView"
android:text="第二层"
android:textSize="30sp"
android:textColor="#ffff00"/> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/thirdView"
android:text="第三层"
android:textSize="15sp"
android:textColor="#ff00ff"
android:gravity="right"/> </FrameLayout>
此时的显示效果为:

看显示效果来说,似乎和之前说的不一样,第三层并不是在布局的左上角,其实是因为我们把这个textview设置宽度为fill_parent,而gravity为right,其实第三层依旧是在坐上层,只不是是这一层内的元素向右对齐罢了。
难道真的是FrameLayout中的子元素完全无法控制自身在布局中的位置吗?其实不是的,android:laytou_gravity属性可以改编控件在布局中的位置
看代码:
framelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstView"
android:text="第一层"
android:textSize="50sp"
android:textColor="#000000"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondView"
android:text="第二层"
android:textSize="30sp"
android:textColor="#ffff00"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thirdView"
android:text="第三层"
android:textSize="15sp"
android:textColor="#ff00ff"
android:layout_gravity="right"
/> </FrameLayout>
结果显示

第三层确实位于布局右边了,所以说FrameLayout布局默认所有的控件都是左上对齐。控件可以通过android:layout_gravity属性控制自己在父控件中的位置。
Android笔记(九) Android中的布局——框架布局的更多相关文章
- Android 笔记之 Android 系统架构
Android笔记之Android系统架构 h2{ color: #4abcde; } a{ color: blue; text-decoration: none; } a:hover{ color: ...
- 《MFC游戏开发》笔记九 游戏中的碰撞判定初步&怪物运动简单AI
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9374935 作者:七十一雾央 新浪微博:http:// ...
- Android笔记: Android版本号
由于有2套版本号 总是对应不准 记下来做过标记 Android 4.3 ----18 Android 4.2---17 Android 4.1---16 Android 4.0.3---15Andro ...
- Android笔记:java 中的数组
在与嵌入式设备通讯的过程中使用的socket通讯 获取的字节流,通常转换为字节数组,需要根据协议将字节数组拆分.对于有规律的重复拆分可以使用,由于java中不能像c中直接进行内存操作例如使用struc ...
- Android笔记:java 中的枚举
部分数据使用枚举比较方便,java中的enmu不如c#中使用方便 记录备忘 以c#中的代码为例 public enum PlayState { /// <summary> /// 关闭 / ...
- Android笔记之Fragment中创建ViewModel的正确方式
之前一直都是这么写的 pageViewModel = ViewModelProviders.of(this).get(PageViewModel.class); //参数this是当前fragment ...
- vue学习笔记(九)vue-cli中的组件通信
前言 在上一篇博客vue学习笔记(八)组件校验&通信中,我们学会了vue中组件的校验和父组件向子组件传递信息以及子组件通知父组件(父子组件通信),上一篇博客也提到那是对组件内容的刚刚开始,而本 ...
- Android笔记:android的适配
public int Dp2Px(Context context, float dp) { final float scale = context.getResources().getDisplayM ...
- Android用户界面设计:框架布局(转)
摘要:框架布局是Android开发者组织视图控件最简单和最有效的布局之一.通过本文,你将学到所有关于框架布局的知识,它们主要用来在屏幕上组织特别的或重叠的视图控件.使用得当的话,很多有趣的Androi ...
随机推荐
- Flink 在IDEA执行时的webui
不过Flink IDEA中执行的webui 需要 flink-runtime-web 包的支持 pom 如下: <dependency> <groupId>org.apache ...
- 【sql server inject】使用动态查询执行sql语句实例
应某少年要求授权测试一个存在报错注入点的站点,可读取数据库名,但是sqlmap执行–os-shell选项就会莫名当掉: 分步骤测试了几次,发现xp_cmdshell是开启状态,但用sqlmap注入却无 ...
- 【C# 开发技巧】 c#窗体关于调试界面和运行界面不一样的原因之一
如下图所示: 原因是因为主窗体属性AutoScaleMode设置为:Font了: 按自己需求将AutoScaleMode设置修改即可. 另外一个可能是系统显示-缩放与布局-要调整到100% 如下图:
- golang中sync.RWMutex和sync.Mutex区别
golang中sync包实现了两种锁Mutex (互斥锁)和RWMutex(读写锁),其中RWMutex是基于Mutex实现的,只读锁的实现使用类似引用计数器的功能. type Mutex f ...
- 有关_meta内容(持续更新)
假设在models里创建了一个类:UserInfo model.UserInfo._meta.app_label #获取该类所在app的app名称 model.UserInfo._meta.model ...
- 读取以key=value形式存储的txt文件
代码片段(假设只有3个key=value): public static void main(String[] args) throws IOException { BufferedReader br ...
- JAVA 读取xml格式的数据
<?xml version="1.0" encoding="UTF-8"?> <column-enums> <type name= ...
- 关于TV工厂菜单参数的具体说明
1.ADC Adjust 此项是针对YPbPr.VGA端口进行处理的,在三路R/G/B或者YPb/Pr信号输入到芯片时候,由于存在硬件上的偏差,导致信号和标准信号存在偏差,需要对信号进行ADC校正.光 ...
- const的用法及它在C语言和C++中的不同
(1)可以定义const常量. (2)Const可以修饰函数的参数和返回值,甚至定义体.被const修饰的东西都受到强制保护. (3)Const修饰成员函数时,用于成员函数前面,则返回值不能作为左值. ...
- mysql查看和设置最大连接数
.查看最大连接数 SHOW VARIABLES LIKE '%max_connections%'; .修改最大连接数 ;