线性布局有LinearLayout类来代表,Android的线性布局和Swing的Box有点相似(他们都会将容器里面的组件一个接一个的排列起来),LinearLayout中,使用android:orientation属性控制布局是水平还是竖直布局(vertical水平,horizontal竖直)

XML属性

相关方法

说明

android:baselineAligned

setBaselineAligned(boolean)

该属性设置为false,将会阻止该布局管理器与它的子元素的基线对其

android:divider

setDividerDrawable(Drawable)

垂直布局两个分按钮之间的分割条

android:gravity

setGravity(int)

设置布局管理器内,组件的对齐方式,属性支持:top,left,right,center_vertical,fill_vertical等

android:measureWithLargestChild

setMeasureWithLargestChildEnabled(boolean)

当该属性设置为true时候,所有带权重的子元素,都会具有最大子元素的最小尺寸

android:orientation

setOrientation(int)

设置布局管理器内,组件的对齐方式,horizontal:水平排列,vertical:垂直排列

LinearLayout子元素常用的XML属性

XML属性

相关方法

说明

Android:layout_gravity

指定该子元素在LinearLayout中的对齐方式

Android:layout_weight

指定该子元素在LinearLayout中所占的权重

属性具体效果:

  1. android:baselineAligned属性

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="horizontal"
    tools:context="com.example.layouttest.MainActivity" > <TextView
    android:id="@+id/t1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="第一个Text"/> <Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="第一个Bton"/> <TextView
    android:id="@+id/t2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="第二个Text"/>
    </LinearLayout>

  2. android:gravity属性
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="right"
    tools:context="com.example.layouttest.MainActivity" > <TextView
    android:id="@+id/t1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="第一个Text"/> <Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="第一个Bton"/> <TextView
    android:id="@+id/t2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="第二个Text"/>
    </LinearLayout>

Android布局管理器(线性布局)的更多相关文章

  1. Android学习系列(二)布局管理器之线性布局的3种实现方式

    转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39643669 LinearLayout是Android控件中的线性布局控件,它包括的子控件 ...

  2. android的布局管理器

    理论上通过setContentView(view)能够把一个view设置到activity中,但当你有很多个view控件的时候,就需要用android的布局管理器来管理view控件了. android ...

  3. android中常用的布局管理器(二)

    接上篇博客 (3)LinearLayout     线性布局管理器 线性布局管理器是将放入其中的组件按照垂直或水平方向来布局,每一行或每一列只能放一个组件,并且不会换行,当组件排列到窗体的边缘后,后面 ...

  4. 第1组UI组件:布局管理器

    1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...

  5. JAVA布局管理器

    JAVA的界面布局原理:由于Java是跨平台语言,使用绝对坐标显然会导致问题,即在不同平台.不同分辨率下的显示效果不一样.Java 为了实现跨平台的特性并且获得动态的布局效果,Java将容器内的全部组 ...

  6. 面试题-Java基础-布局管理器

    1.什么是布局管理器? 布局管理器用来在容器中组织组件.

  7. 5、Java Swing布局管理器(FlowLayout、BorderLayout、CardLayout、BoxLayout、GirdBagLayout 和 GirdLayout)

    5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小而相应改变,不变的只是其相对位置,布局管理器比较难以控制,一般只在界面大小需要改是才用,但即使这 ...

  8. Java-Swing常用布局管理器

    http://www.cnblogs.com/hthuang/p/3460234.html   5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小 ...

  9. Qt之布局管理器

    简述 Qt的布局系统提供了一个简单的和强有力的方式,来自动排列窗口子控件布局. 所有QWidget子类可以使用布局来管理他们的子控件.QWidget::setLayout()函数可以为一个控件布局.当 ...

随机推荐

  1. 优雅的让Fragment监听返回键

    转载请注明出处:http://write.blog.csdn.net/postedit/40507387 Activity可以很容易的得到物理返回键的监听事件,而Fragment却不能.假设Fragm ...

  2. WordPress ‘get_allowed_mime_types’函数安全漏洞(2)

    漏洞名称: WordPress ‘get_allowed_mime_types’函数安全漏洞 CNNVD编号: CNNVD-201309-169 发布时间: 2013-09-13 更新时间: 2013 ...

  3. 分布式文件系统FastDFS安装与配置(单机)

    安装包如下:fastdfs-nginx-module_v1.16.tar.gzFastDFS_v5.05.tar.gzlibfastcommon-master.zipnginx-1.8.0.tar.g ...

  4. web.xml中的contextConfigLocation的作用

    在web.xml中通过contextConfigLocation配置spring,contextConfigLocation 参数定义了要装入的 Spring 配置文件. 如果想装入多个配置文件,可以 ...

  5. Linux学习笔记9——make和Makefile

    一,Makefile的文件名 默认的情况下,make命令会在当前目录下按顺序找寻文件名为“GNUmakefile”.“makefile”.“Makefile”的文件,大部分情况下,make命令都支持m ...

  6. ZOJ Problem Set - 3758 素数

    Singles' Day Time Limit: 2 Seconds Memory Limit: 65536 KB Singles' Day(or One's Day), an unofficial ...

  7. lightoj 1018 dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cst ...

  8. android 国内sdk下载地址及代理, android 环境搭建

    http://www.androiddevtools.cn/ http://www.cnblogs.com/bjzhanghao/archive/2012/11/14/android-platform ...

  9. 终端command总结

    Ctrl+Alt+Delete Ctrl+Shift+Esc Ctrl+D Alt+F4 Shift+F10 win+m Ctrl+Alt+. Ctrl+A Ctrl+S osk taskmgr cm ...

  10. VS2012的安装项目只能用InstallShield Limited Edition[附资源下载]

    以前版本的Visual Stuido中安装项目都可以使用微软自家的Visual Studio Installer,但是到了VS2012这一切都变了,只能用InstallShield Limited E ...