LinearLayout是线性布局控件:要么横向排布,要么竖向排布

常用属性:

android:gravity------------设置的是控件自身上面的内容位置

android:layout_gravity-----设置控件本身相对于父控件的显示位置

android:layout_weight----- 给控件分配剩余空间

先给大家展示一下导图:

知识点详解(演示效果方便组件没有设置id)

(1)gravity和Layout_gravity

android:gravity 属性是对该view中内容的限定.比如一个button 上面的text. 你可以设置该text 相对于view的靠左,靠右等位置.

android:layout_gravity是用来设置该view相对与父view 的位置.比如一个button 在linearlayout里,你想把该button放在linearlayout里靠左、靠右等位置就可以通过该属性设置.

(2)weight权重(以水平为例)

(a)当width = 0或者 width = wrap_content的时候,按照权重比例计算!:2: 3

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

android:id="@+id/text1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@android:color/holo_red_dark"

android:text="Text1"/>

android:id="@+id/text2"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="2"

android:background="@android:color/holo_blue_bright"

android:text="Text2"/>

android:id="@+id/text3"

android:layout_width="0dp"

android:layout_height="match_parent"

android:background="@android:color/white"

android:layout_weight="3"

android:text="Text3"/>

(b)当width = fill_parent/match_parent的时候

第一步:当三个都为match_parent的时候屏幕只有一个 1 -3 = -2;

第二步:计算每个TextView占有的比例 1/6,2/6,3/6;

第三步: 1 -2*1/6 = 2/3; 1 - 2*2/6 = 1/3; 1 - 2*3/6 = 0;

第四步:2:1:0

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

android:id="@+id/text1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@android:color/holo_red_dark"

android:text="Text1"

android:gravity="center"

android:textSize="40sp"/>

android:id="@+id/text2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="2"

android:background="@android:color/holo_blue_bright"

android:text="Text2"

android:gravity="center"

android:textSize="40sp"/>

android:id="@+id/text3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/white"

android:layout_weight="3"

android:text="Text3"

android:gravity="center"

android:textSize="40sp"/>

(3)分割线

android:layout_marginLeft="20sp"

android:layout_marginRight="20sp"

android:layout_width="3"

android:layout_height="match_parent"

android:background="#ff00ee" />

案例(底部导航)

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

>

android:layout_width="match_parent"

android:layout_height="80sp"

android:layout_gravity="bottom"

android:background="@android:color/holo_purple">

android:layout_width="0sp"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="vertical"

android:gravity="center">

android:layout_width="60dp"

android:layout_height="60dp"

android:src="@mipmap/ic_launcher"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="one"

android:textSize="20sp"/>

android:layout_marginLeft="20sp"

android:layout_marginRight="20sp"

android:layout_width="3"

android:layout_height="match_parent"

android:background="#ff00ee" />

android:layout_width="0sp"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="vertical"

android:gravity="center">

android:layout_width="60dp"

android:layout_height="60dp"

android:src="@mipmap/ic_launcher"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="two"

android:textSize="20sp"/>

android:layout_marginLeft="20sp"

android:layout_marginRight="20sp"

android:layout_width="3"

android:layout_height="match_parent"

android:background="#ff00ee" />

android:layout_width="0sp"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="vertical"

android:gravity="center">

android:layout_width="60dp"

android:layout_height="60dp"

android:src="@mipmap/ic_launcher"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="three"

android:textSize="20sp"/>

以上内容给大家介绍了Android布局之LinearLayout线性布局的相关知识,希望大家喜欢。

Android的 线性布局,Android布局之LinearLayout线性布局相关推荐

  1. Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

    UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...

  2. 精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...

    标题图 UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个 ...

  3. android linearlayout最大高度,Android中最简单最常用的LinearLayout线性布局

    原标题:Android中最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认为Relativ ...

  4. Android布局——Linearlayout线性布局

    Android最简单最常用的LinearLayout线性布局 一.认识LinearLayout 线性布局是Android中较为常用的布局方式,使用LinearLayout标签.线性布局主要有两种形式, ...

  5. android使用桢布局,Android 常用布局

    Android的布局有: LinearLayout线性布局 RelativeLayout            相对布局 FrameLayout单桢布局 TableLayout表格布局 GridLay ...

  6. Android零基础入门第25节:最简单最常用的LinearLayout线性布局

    原文:Android零基础入门第25节:最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认 ...

  7. Android 应用开发(36)---LinearLayout(线性布局)

    LinearLayout(线性布局) 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局),RelativeLayout(相对布局),Table ...

  8. Android 应用开发(第3章)线性布局LinearLayout

    1.线性布局(LinearLayout) 线性布局是Android中较为常用的布局方式,它使用<LinearLayout>标签.LinearLayout 线性布局有两种,分别是水平线性布局 ...

  9. android线性布局设置控件固定在底部,Android UI组件LinearLayout线性布局详解

    LinearLayout 线性布局,该布局的继承关系: 1. 什么是线性布局 通俗的说感觉起来和线有关,参照线的特点,有么是横向的,要么是竖向的. LinearLayout是线性布局控件,它包含的子控 ...

  10. 【Android 】零基础到飞升 | LinearLayout(线性布局)

    2.2.1 LinearLayout(线性布局) 本节引言 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局),RelativeLayout( ...

最新文章

  1. 数字图像处理笔记一 - 图像采集(空间分辨率和幅度分辨率)
  2. java中final是修饰符么_Java final修饰符详解
  3. 在子类中调用父类的方法super
  4. 垂涎欲滴!30个美味的食品类移动应用程序【下篇】
  5. 徐明星斥资超4亿香港买壳:史玉柱女儿现身股东行列
  6. python多线程学了多久_Python多线程一学就会!
  7. java多线程-线程的实现方式
  8. java 毕向东 笔记_毕向东Java基础部分笔记
  9. 纵横公路造价软件学习_纵横公路造价软件教程
  10. Cortex-M的M0,M+,M3,M4,M7几种内核的简单区别
  11. TypeError: Object of type xxx is not JSON serializable错误解决
  12. python字典怎么获得_python怎样获取字典中前十个
  13. JS之获取银行卡信息
  14. 集合的基本运算及文氏图
  15. 网站采集器-免费任意网页数据采集器
  16. ubuntu 64bit 兼容运行32bit 的方法
  17. 【渝粤题库】陕西师范大学201511先秦历史散文研究 作业(专升本)
  18. C++ 不快乐的函数 1
  19. c语言割线法求方程跟,分别用牛顿法和割线法求解方程 x^3-6x^2+9x-2=0在区间[3,4]上的近似根.要求满足精度|x*-xk|...
  20. A Game of Thrones(103)

热门文章

  1. ASP.NET伪静态
  2. 一次性删除maven本地仓库下的.lastUpdated 结尾的文件
  3. java日期去掉时分秒,只保留年月日
  4. 4.1 数据库的设置
  5. CURL命令模拟Http Get/Post以及带cookies调用接口
  6. 谈谈如何用eoLinker管理各类API接口
  7. 55. GridPanel中getSelectionModel详解
  8. 补全aaz288 可能有问题的过程 P_COMPL_AAZ288
  9. android shape 使用小结
  10. socket与模拟http请求