android五大布局之线性布局。

  1.线性布局的特点:各个子元素彼此连接,中间不留空白

  

  而今天我们要讲解的就是第一个布局,LinearLayout(线性布局),我们屏幕适配的使用

  用的比较多的就是LinearLayout的weight(权重属性),下面写个案例来表明

  

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="#FFC90E"
> </LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:orientation="vertical"
android:background="#DA70D6"
> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="" >
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="#66CDAA"
android:orientation="horizontal"
> <TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFF663"
android:layout_weight="" />
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#E82917"
android:layout_weight="" />
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFF663"
android:layout_weight="" /> </LinearLayout> </LinearLayout>
</LinearLayout>

效果图为:

android:layout_gravity 本元素相对于父元素的重力方向

android:gravity 本元素所有子元素的重力方向

android:orientation 线性布局以列或行来显示内部子元素

android:layout_weight 子元素对未占用空间水平或垂直分配权重值

当 android:orientation="vertical" 时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。!!!!

当 android:orientation="horizontal" 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。!!!!

android:layout_gravity 和 android:gravity 的区别

android:gravity对元素本身起作用-本身元素显示在什么位置

android:layout_gravity相对与它的父元素-元素显示在父元素的什么位置。

如:Button控件

android:layout_gravity 表示button在界面上的位置

android:gravity表示button上的字在button上的位置。

可选值[多选时用“|”分开]

top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。

top 将对象放在其容器的顶部,不改变其大小.

bottom 将对象放在其容器的底部,不改变其大小.

left将对象放在其容器的左侧,不改变其大小.

right将对象放在其容器的右侧,不改变其大小.

center_vertical 将对象纵向居中,不改变其大小.

垂直对齐方式:垂直方向上居中对齐。

fill_vertical 必要的时候增加对象的纵向大小,以完全充满其容器. 垂直方向填充

center_horizontal 将对象横向居中,不改变其大小水平对齐方式:水平方向上居中对齐

fill_horizontal 必要的时候增加对象的横向大小,以完全充满其容器. 水平方向填充

center 将对象横纵居中,不改变其大小.

fill 必要的时候增加对象的横纵向大小,以完全充满其容器.

clip_vertical 附加选项,用于按照容器的边来剪切对象的顶部和/或底部的内容. 剪切基于其纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部.垂直方向裁剪

clip_horizontal 附加选项,用于按照容器的边来剪切对象的左侧和/或右侧的内容. 剪切基于其横向对齐设置:左侧对齐时,剪切右侧;右侧对齐时剪切左侧;除此之外剪切左侧和右侧.水平方向裁剪

例子

TextView要让文本垂直/水平居中显示,有两种情况需要考虑:

1、layout_width/layout_height为wrap_content,此时要让TextView在父控件上居中显示,必须设置layout_gravity=”center”。

2、layout_width/layout_height为fill_parent,此时由于TextView已占据父窗体所有空间,必须设置gravity=”center”。

android—-线性布局的更多相关文章

  1. Android线性布局(Linear Layout)

    Android线性布局(Linear Layout) LinearLayout是一个view组(view group),其包含的所有子view都以一个方向排列,垂直或是水平方向.我们能够用androi ...

  2. Android 线性布局(LinearLayout)相关官方文档 - 指南部分

    Android 线性布局(LinearLayout)相关官方文档 - 指南部分 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用 ...

  3. Android 线性布局(LinearLayout)相关官方文档 - 布局參数部分

    Android 线性布局(LinearLayout)相关官方文档 - 布局參数部分 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...

  4. Android线性布局

    线性布局 LinearLayout 是一个视图组,用于使所有子视图在单个方向(垂直或水平)保持对齐. 您可以使用 android:orientation 属性指定布局方向. LinearLayout ...

  5. android 线性布局

    activity_main.xml线性布局 <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  6. Android线性布局和帧布局

    第二次,本牛崽十分从容,今天咱们来讲讲Android Q之布局,我遇到的问题与自己学到的,大牛不要嘲笑哈,有错误可以指出来,本牛崽看到就改了. 今天我的学长跟我们开始了布局,布局看资料说好像有5种,又 ...

  7. [android] 线性布局和布局的组合

    /****************2016年4月25日 更新******************************/ 知乎:对于开发者来说,Android 的开发者选项里有哪些实用的功能? 汤涛 ...

  8. Android 线性布局 LinearLayout

    垂直布局 vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  9. iOS - starckView 类似Android线性布局

    同iOS以往每个迭代一样,iOS 9带来了很多新特性.UIKit框架每个版本都在改变,而在iOS 9比较特别的是UIStackView,它将从根本上改变开发者在iOS上创建用户界面的方式.本文将带你学 ...

随机推荐

  1. C#之关机事件

    一.背景 做了个APP,通过向下位机发送串口数据,然后通过串口去控制多路光源,现在的问题来了,若是电脑强行关机,而APP又没在电脑关机前做任何动作,导致电脑已经关机了,而下位机控制的灯源还在工作.所以 ...

  2. 【bzoj1426】收集邮票

    题目描述 有n种不同的邮票,皮皮想收集所有种类的邮票.唯一的收集方法是到同学凡凡那里购买,每次只能买一张,并且买到的邮票究竟是n种邮票中的哪一种是等概率的,概率均为1/n.但是由于凡凡也很喜欢邮票,所 ...

  3. java后端制作MD5加密

    由于一次业务的需要,我制作了一次密码的修改子业务. 当用户忘记密码的情况下,我需要动态的发给他一个6位的随机密码,通过即时通,短信,微信等.并同时修改数据库中的原密码为这6位的随机密码.让用户再去修改 ...

  4. GCC 编译优化指南(转)

    GCC 编译优化指南(转) http://www.jinbuguo.com/linux/optimize_guide.html 作者:金步国 版权声明 本文作者是一位开源理念的坚定支持者,所以本文虽然 ...

  5. NOIp2014 解题报告

    有史以来第一届面向社会征题的NOIp结束了.最开始以为面向社会征题会很难,但是这是我参加的最水的一次NOIp了. 由于停了两月的课,所以现在正在补文化科目就没时间打代码了.所以所有的题目就均不给出代码 ...

  6. python习题 (1):login

    #!/uer/bin/env python # _*_ coding: utf-8 _*_ import sys retry_limit = 3 retry_count = 0 account_fil ...

  7. push 到下一界面明显卡顿的现象

    今天搭建界面,界面间的跳转使用了 push方法,结果发现界面间转换时有明显的卡顿现象,并没有做过数据请求之类的处理,所以感觉好神奇.以前好像也遇到过,当时在push 到的下级界面加个背景色.现在重新这 ...

  8. Macbook Pro 使用小记

    本周到手Macbook Pro,很激动.刚刚使用了几天,简单记下自己的感受.   Macbook Pro的硬件配置和做工真没得说,非常完美. 触控板很强大.很好用,鼠标可以基本不用了,但要稍微学习一下 ...

  9. Ubuntu 配置有线网 IP

    方法1: 最直接的办法,就是在右上端的网络那里点设置,然后add,选以太网,然后IPV4里,手动设置 -- add IP -- 填入IP地址.网关.子网掩码,OK. 方法2,3见网上教程: Ubunt ...

  10. 利用WCF创建简单的RESTFul Service

    1):用VS2013创建一个WCF的工程,如下图所示: 2):我们来看一下默认状态下的config文件内容,这里的内容我们会再后续的步骤中进行修改 <?xml version="1.0 ...