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. .NET WebForm简介

    WebForm简介 微软开发的一款产品,它将用户的请求和响应都封装为控件.让开发者认为自己是在操作一个windows界面.极大地提高了开发效率. C/S(客户端) 主要是在本机执行(每一个客户端是独立 ...

  2. SQL2005中的事务与锁定(八)- 转载

    ------------------------------------------------------------------------ -- Author : happyflystone - ...

  3. Hadoop编程1:天气数据AWK & MapReduce

    本文介绍通过AWK和MapReduce两种方式统计出每年温度到最高气温直.awk速度虽然快,而且简短,但是数据量巨大到时候,就遇到力瓶颈,及时分布式执行awk脚本,也会出现机器死掉等问题,需要容错机制 ...

  4. pyenv ipython jupyter

    pyenv pyenv  依赖安装 yum -y install git gcc make patch zlib-devel gdbm-devel openssl-devel sqlite-devel ...

  5. WF4.0入门(一)

    WF的全称是Windows Workflow Foundation .这是 Microsoft 快速构建基于工作流的应用程序的编程模型.引擎和工具.NET Framework 4 中这个 WF 版本更 ...

  6. 2015弱校联盟(1) - B. Carries

    B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...

  7. Hibernate的关联映射——单向N-1关联

    Hibernate的关联映射--单向N-1关联 N-1是非常常见的关联关系,最常见的父子关系也是N-1关联,单向的N-1关联只需从N的一端可以访问1的一端. 为了让两个持久化类能够支持这种关联映射,程 ...

  8. 【转】对硬盘进行分区时,GPT和MBR区别。

    在Windows 8或8.1中设置新磁盘时,系统会询问你是想要使用MBR还是GPT分区.GPT是一种新的标准,并在逐渐取代MBR. GPT带来了很多新特性,但MBR仍然拥有最好的兼容性.GPT并不是W ...

  9. uploadify springMVC

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  10. bzoj 4415: [Shoi2013]发牌

    4415: [Shoi2013]发牌 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 173  Solved: 124[Submit][Status][ ...