框架布局没有任何定位方式,所有的控件都会摆放在布局的左上角。

代码示例:

   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中的布局——框架布局的更多相关文章

  1. Android 笔记之 Android 系统架构

    Android笔记之Android系统架构 h2{ color: #4abcde; } a{ color: blue; text-decoration: none; } a:hover{ color: ...

  2. 《MFC游戏开发》笔记九 游戏中的碰撞判定初步&怪物运动简单AI

    本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9374935 作者:七十一雾央 新浪微博:http:// ...

  3. Android笔记: Android版本号

    由于有2套版本号 总是对应不准 记下来做过标记 Android 4.3 ----18 Android 4.2---17 Android 4.1---16 Android 4.0.3---15Andro ...

  4. Android笔记:java 中的数组

    在与嵌入式设备通讯的过程中使用的socket通讯 获取的字节流,通常转换为字节数组,需要根据协议将字节数组拆分.对于有规律的重复拆分可以使用,由于java中不能像c中直接进行内存操作例如使用struc ...

  5. Android笔记:java 中的枚举

    部分数据使用枚举比较方便,java中的enmu不如c#中使用方便 记录备忘 以c#中的代码为例 public enum PlayState { /// <summary> /// 关闭 / ...

  6. Android笔记之Fragment中创建ViewModel的正确方式

    之前一直都是这么写的 pageViewModel = ViewModelProviders.of(this).get(PageViewModel.class); //参数this是当前fragment ...

  7. vue学习笔记(九)vue-cli中的组件通信

    前言 在上一篇博客vue学习笔记(八)组件校验&通信中,我们学会了vue中组件的校验和父组件向子组件传递信息以及子组件通知父组件(父子组件通信),上一篇博客也提到那是对组件内容的刚刚开始,而本 ...

  8. Android笔记:android的适配

    public int Dp2Px(Context context, float dp) { final float scale = context.getResources().getDisplayM ...

  9. Android用户界面设计:框架布局(转)

    摘要:框架布局是Android开发者组织视图控件最简单和最有效的布局之一.通过本文,你将学到所有关于框架布局的知识,它们主要用来在屏幕上组织特别的或重叠的视图控件.使用得当的话,很多有趣的Androi ...

随机推荐

  1. Elasticsearch服务器开发(第2版).pdf 含目录

    Elasticsearch服务器开发(第2版) 介绍: <Elasticsearch服务器开发(第2版)>这一版针对Elasticsearch的新版本更新了内容,增加了第1版中遗漏的重要内 ...

  2. ABAP语法篇2 内表操作语法

    VALUE MOVE-CORRESPONDING CORRESPOING FOR REDUCE GROUP BY FILTER VALUE语法: 结构赋值 ... VALUE dtype | #(  ...

  3. Java Thread Local – How to use and code sample(转)

    转载自:https://veerasundar.com/blog/2010/11/java-thread-local-how-to-use-and-code-sample/ Thread Local ...

  4. Semi-supervised learning for Text Classification by Layer Partitioning

    本文是arxiv上一篇较短的文章,之所以看是因为其标题中半监督和文本分类吸引了我.不过看完之后觉得所做的工作比较少,但想法其实也挺不错. 大多数的半监督方法都选择将小扰动施加到输入向量或其表示中,这种 ...

  5. ElasticSearch RestHighLevelClient 通用操作

    项目中使用到ElasticSearch作为搜索引擎.而ES的环境搭建自然是十分简单,且本身就适应于分布式环境,因此这块就不多赘述.而其本身特性和查询语句这篇博文不会介绍,如果有机会会深入介绍. ​ 所 ...

  6. 20191104-基于Python计数排序算法分析

    计数排序 计数排序算法没有用到元素间的比较,它利用元素的实际值来确定它们在输出数组中的位置,也就是说元素从未排序状态变为已排序状态的过程,是由额外空间的辅助和元素本身的值决定的,将每个元素出现的次数记 ...

  7. 解决warning: Clock skew detected. Your build may be incomplete

    原因:机器系统时间与文件时间不一致 解决:更新所有文件的时间后重新编译 find . -type f | xargs -n 5 touch make clean make xargs  -n num ...

  8. QQ、微信 唯一登陆设计

    唯一登陆设计指一个账号可以在多个不同的客户端进行登陆,例如PC.Android.IOS等.每一个客户端就会生成一个对应的tokan,相当于生成三个token分别对应不同的客户端. 但是同一个客户端同时 ...

  9. WebClient 下载文件

    WebClient用法小结(转载)   如果只想从特定的URI请求文件,则使用WebClient,它是最简单的.NET类,它只用一两条命令执行基本操作,.NET FRAMEWORK目前支持以http: ...

  10. 使用async和await的异步编程

    异步编程模型(TAP)提供了抽象的异步代码.异步代码看起来和同步代码没什么大的区别,无非多个了两个关键字(async和await).但是代码的执行顺序并没看起来那么简单,代码的执行顺序根据cpu资源的 ...