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

代码示例:

   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(PDF版 内含目录)

    深入理解ElasticSearch 介绍: 本书涵盖了Elasticsearch的许多中高级功能,并介绍了缓存.ApacheLucene库以及监控等模块的内部运作机制.其中,还涉及一些实用案例,比如配 ...

  2. cudaGetDevice() failed. Status: cudaGetErrorString symbol not found.怎么解决

    我是在使用anaconda的Spyder写一个数字识别的任务的时候遇到这个问题的,当时我以为是我的函数库有问题,然后安装了很多东西都没用,然后百度的答案都很模糊,在我尝试了一天一下午之后,找到了问题原 ...

  3. python 调 java(胶水就是胶水)

    java门外汉用python调java, 一.安装java环境(linux) 1.首先要去下载好JDK,Java SE 8的官方网址是http://www.oracle.com/technetwork ...

  4. 3.WXML语法

    标签必须完全闭合 大小写敏感

  5. eNSP上VLAN的基础的配置及access接口

    本实验模拟公司内部,为不同的部门划分不同的VLAN ,形成的不同广播域,来保护信息的安全,拓扑图如下所示

  6. Rust零碎总结

    1.Rust里没有null的概念,但是实际上有很多地方是需要null的概念的,这个时候就可以用Option来代替,它是泛型T的一个包装类,就是C#里的int?或Java里的Optional: [但反序 ...

  7. lnmp 是不是该吐吐槽

    lnmp 提供提供了便捷 , 并且手也伸的挺长的,它已不仅仅是个服务器环境那么简单 作为服务器继承环境来讲,可能每个人的认知程度不一,总之用了它需要服从它的规则 但从个人感觉上,其埋的坑还是让人不适, ...

  8. Python19之函数和过程

    一.函数和过程 函数和过程都是指一段实现特定功能的代码段,如果该代码段有返回值则称为函数,否则称为过程. 注:Python中只有函数而没有过程,就算是函数体内没有return语句返回一个值,Pytho ...

  9. django使用pyecharts(4)----django加入echarts_增量更新

    四.Django 前后端分离_定时增量更新图表 1.安装 djangorestframework linux pip3 install djangorestframework windows pip ...

  10. EAFP vs LBYL

    EAFP vs LBYL 检查数据可以让程序更健壮,用术语来说就是防御性编程.检查数据的时候,有EAFP和LBYL两种不同的编程风格,具体的意思如下: LBYL: Look Before You Le ...