线性布局有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. <转>SFTP 和FTPS的区别是什么?

    SFTP 和FTPS都是为ftp连接加密,协议非常相似. 一个是借助ssl协议加密,一个时借助ssh加密. ssl是为http/smtp等加密设计的,ssh是为telnet/ftp等加密.建立传输通道 ...

  2. android 一个页面内 多个listview的实现

    如果很平常的两个listview组件竖直放在linearLayout布局中,结果是: 两个listview 很独立,中间似乎有个分割线,完全吧他们分离了,各自独立滚动,如果上面的listview把整个 ...

  3. 几种交换两个数函数(swap函数)的写法和解析

    #include <iostream> using namespace std; /*值传递,局部变量a和b的值确实在调用swap0时变化了,当结束时,他们绳命周期结束*/ void sw ...

  4. bzoj3437

    练一下斜率优化 ..] of int64; q,a,b:..] of longint; i,n,h,t,j:longint; function g(j,k:longint):double; var a ...

  5. ☀【HTML5】Modernizr

    Modernizr 使用Modernizr探测HTML5/CSS3新特性

  6. JavaScript高级程序设计10.pdf

    String类型有几种操作字符串的方法 concat()方法拼接任意多个字符串,不修改原字符串 var stringValue=“hello ”; var result=stringValue.con ...

  7. 《University Calculus》-chaper8-无穷序列和无穷级数-泰勒定理的证明

    泰勒定理: 证明:

  8. Kong for Enterprise | Kong - Open-Source API and Microservice Management Layer

    Kong for Enterprise | Kong - Open-Source API and Microservice Management Layer undefined

  9. hud 1241 dfs连同块

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  10. WinForm------自定义YearMonthEdit组件

    转载: http://www.cnblogs.com/axing/p/3201066.html 注意: 1.需要在vs里面,添加一个YearMonthEdit组件,然后将链接里面的代码拷贝到里面 2. ...