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. RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本━新增岗位管理-WinForm部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本 新增岗位管理-WinForm部分 岗位(职位)管理模块主要是针对组织机构的岗位(职位)进行管理,包括:增加.修改. ...

  2. 《30天自制操作系统》14_day_学习笔记

    harib11a--harib11c: 继续测试性能:我们在harib10h中进行了定时链表结构的改进“消除了移位处理”.下面我们设定490个定时器(它们都被设定启动50天才超时)来测试一下改进的效果 ...

  3. CPlus播放多媒体之播放声音

    1.头文件需要<mmsystem.h>,但是之前需要包含<windows.h> 2.预处理#pragma comment<lib,"winmm.h"& ...

  4. 配置本地光盘为yum源

    挂载cd-rom mount /dev/cdrom /mnt http://javaarm.com/faces/display.xhtml?tid=3520 关闭selinux vi /etc/sys ...

  5. Python 时间和日期模块的常用例子

    获取当前时间的两种方法 import datetime,time now = time.strftime("%Y-%m-%d %H:%M:%S") print now now = ...

  6. Repeater控件三层嵌套-内层Repeater添加绑定事件

    用Repeater三层嵌套,最外层Repeater可以生成自己的ItemCommand事件.但接下来中间层因为是嵌套了的,所以无法在属性窗口中生成自己的事件.如果手动敲入则无效. 解决办法是需要通过编 ...

  7. 高性能完成端口socket服务(IOCP)

    1. Winsock IO模型之IOCP模型 来自csdn blog,版权声明:本文为博主原创文章,未经博主允许不得转载. 我这里记录下,不算转载吧 http://blog.csdn.net/lost ...

  8. pageX/Y, offset(), position(), scrollTop(), screenX/Y, clientX/Y, pageX/Y

    event.pageX get mouse position Description: The mouse position relative to the left edge of the docu ...

  9. 02-FPGA设计流程介绍——小梅哥FPGA设计思想与验证方法视频教程配套文档

    芯航线——普利斯队长精心奉献 课程目标: 1.了解并学会FPGA开发设计的整体流程 2.设计一个二选一选择器并进行功能仿真.时序仿真以及板级验证 实验平台:芯航线FPGA开发板.杜邦线 实验内容: 良 ...

  10. 你不知道的Java类

    1.StrSubstitutor StrSubstitutor是一个很特殊的类,在String中使用${key}的方法在形成了一个可配置的模板,new一个HashMap使用HashMap替换Strin ...