1.简介

LinearLayout为安卓三大常用布局中的线性布局。其中,线性布局又分为水平线性布局和垂直线性布局。视图如下所示:

水平布局

垂直布局

2.构建

在安卓布局中,往往需要我们进行嵌套布局,以下图为例

重点如下所示:

2.1 android:orientation="horizontal/ertical":该属性表示布局为水平方式或垂直方式。

2.2 android:layout_weight="A":该属性表示子布局占总布局的大小,所有的子布局数字相加之和Sum(A),子布局数A/Sum(A)即为所占比例。

2.3 android:gravity="start/center/end/bottom":该属性表示在该布局中的部件处于水平方向的开始位置,居中,水平方向的结束位置或者最下端。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="example.linearlayout.Activity1" >

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="1" >

<Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/bu1" />

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="end" >

<Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/bu2" />

</LinearLayout>
    </LinearLayout>

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_weight="1" >

<Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/bu3" />

</LinearLayout>

<LinearLayout                              
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="1"
        android:gravity="bottom" >             //它将它的部件置于最下端,于是它的子布局也会至于最下端,如最后一张图所示

<Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/bu5" />

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"         //这里高度调整为自适应,于是它的高度和按钮高度一致
            android:orientation="vertical"
            android:gravity="end">

<Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/bu4" />

</LinearLayout>
    </LinearLayout>
</LinearLayout>

Android开发--LinearLayout的应用的更多相关文章

  1. Android开发——LinearLayout和RelativeLayout的性能对比

    0. 前言 我们都知道新建一个Android项目自动生成的Xml布局文件的根节点默认是RelativeLayout,这不是IDE默认设置,而是由android-sdk\tools\templates\ ...

  2. Android开发之自定义的ListView(UITableViewController)

    Android开发中的ListView, 顾名方法思义,就是表视图.表示图在iOS开发中就是TableView.两者虽然名称不一样,但是其使用方法,使用场景以及该控件的功能都极为相似,都是用来展示大量 ...

  3. Android开发之自定义组件和接口回调

    说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...

  4. Android开发之基本控件和详解四种布局方式

    Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...

  5. Android开发之画图的实现

    Android开发之画图的实现    四天前上完安卓的第一节课,真的是一脸懵逼,尽管熊哥说和java是差不多的,然而这个包和那个包之间的那些转换都是些什么鬼呀!!!但是四天的学习和操作下来,我觉得安卓 ...

  6. Android开发-之认识palette

    Android开发中,Google工程师已经给我们封装好了很多的按钮,使得我们在开发中非常的方便和便捷. 那么今天就来认识一下常用的按钮,那么在之前的课程中我已经详细讲过了Button按钮,那么这里就 ...

  7. Android开发-之五大布局

    在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...

  8. Android开发重点难点1:RelativeLayout(相对布局)详解

    前言 啦啦啦~博主又推出了一个新的系列啦~ 之前的Android开发系列主要以完成实验的过程为主,经常会综合许多知识来写,所以难免会有知识点的交杂,给人一种混乱的感觉. 所以博主推出“重点难点”系列, ...

  9. Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)

    前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...

随机推荐

  1. C# 遍历类的属性并取出值

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精    今天有点胡思乱想,想遍历MVC Model的属性并 ...

  2. sp_executesql

    execute相信大家都用的用熟了,简写为exec,除了用来执行存储过程,一般都用来执行动态Sql  sp_executesql,sql2005中引入的新的系统存储过程,也是用来处理动态sql的, 如 ...

  3. C#实现鸽巢排序

    /// <summary> /// 鸽巢排序 /// 创建一个长度大于等于待排序数组array元素中最大值的标记数组mark, /// 将数组array中元素值个数映射到mark数组中. ...

  4. Pyhton 学习总结 21 :fileinput模块

    fileinput模块可以对一个或多个文件中的内容进行迭代.遍历等操作.该模块的input()函数有点类似文件readlines()方法,区别在于前者是一个迭代对象,需要用for循环迭代,后者是一次性 ...

  5. Qt之多窗口切换

    在新建对象(下一页面)的时候,把自身的this指针带进去,然后把自身hide(),隐藏起来,在(下一页面中)要回退的时候只需通过: 1. parentWidget()->show(); //显示 ...

  6. jacob 多个web项目报错 jacob-1.14.3-x64.dll already loaded in another classloader jacob

    多个web项目报错 jacob-1.14.3-x64.dll already loaded in another classloader jacob 这个问题困扰了很久,网上很多解决方案,很多都不成功 ...

  7. ruby on rails on windows

    这次想系统学会rails,最终目标是将redmine改造成顺手的工具,主要的手段就是开发redmine插件.虽然网上都推荐使用类Unix系统,可手头只有win7系统,就安装了. 难免会遇到这样那样的问 ...

  8. php中curl模拟浏览器来传输数据

    cURL可以使用URL的语法模拟浏览器来传输数据, 因为它是模拟浏览器,因此它同样支持多种协议,FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以 ...

  9. Linux内核链表深度分析【转】

    本文转载自:http://blog.csdn.net/coding__madman/article/details/51325646 链表简介: 链表是一种常用的数据结构,它通过指针将一系列数据节点连 ...

  10. HTML 5 的data-* 自定义属性

    HTML 5 增加了一项新功能是 自定义数据属性 ,也就是  data-* 自定义属性.在HTML5中我们可以使用以 data- 为前缀来设置我们需要的自定义属性,来进行一些数据的存放.当然高级浏览器 ...