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 ...
随机推荐
- Internet Download Manager 快速下载插件,破解版
下载下来直接双击绿化按钮即可. 软件链接 : https://pan.baidu.com/s/1agK3cLtjJzXcGEgsuv5mVQ 提取码: ckm7
- intellij tomcat配置
目录 intellij tomcat配置 @(目录) intellij tomcat配置 如上图标注 1 所示,我们可以切换随时为项目切换不同的容器. 如上图标注 2 所示,我们可以指定给运行的容器设 ...
- 安卓apk反编译
在win环境反编译安卓APP的.apk文件 安卓apk 反编译为 Java源码图文教程 Android安全攻防战,反编译与混淆技术完全解析(上)
- git的使用学习(四)git的远程仓库
1.远程仓库介绍 到目前为止,我们已经掌握了如何在Git仓库里对一个文件进行时光穿梭,你再也不用担心文件备份或者丢失的问题了. 可是有用过集中式版本控制系统SVN的童鞋会站出来说,这些功能在SVN里早 ...
- centos docker 修改默认存储路径
1.修改配置 将--graph /mnt/docker添加在docker.service文件中的ExecStart字段后面,其中/mnt/docker为你需要修改的存储目录 $ vim /usr/li ...
- [转帖]负载均衡 LVS+Keepalived
负载均衡 LVS+Keepalived https://www.cnblogs.com/jicki/p/5546862.html 改天试试 一直没搞过. 系统 CentOS 5.6 X64 物理机 ...
- [Oracle] - 关于星期(IW和WW)的算法
1. 查看数据库字符集(如果字符集不同,可能显示乱码) select DECODE(parameter, 'NLS_TERRITORY', 'TERRITORY', 'NLS_LANGUAGE', ' ...
- java FastJson的使用总结
1.前言 1.1.FastJson的介绍: JSON(javaScript Object Notation)是一种轻量级的数据交换格式.主要采用键值对({"name": " ...
- C语言的关键字和数据类型
C语言关键字 C语言数据类型
- Fabric交易流程
(内容可能有些乱,请见谅,日后会对格式进行整理!) #### 在1.0及以后的版本中,客户端应用会先向Fabric CA申请用户所需要的Fabric中的准入证书,用于签名提案以及交易,然后由客户端(A ...