Android LinearLayout 线性布局

LinearLayout 线性布局
LinearLayout 按照垂直或者水平的顺序依次排列子元素,每一个子元素位于前一个元素之后。
LinearLayout 中的子元素属性:android:layout_weight生效,它用于描述该子元素在剩余空间中占有的大小比例,加入一行只有一个文本框,那么它的默认值就是0,如果一行中有两个等长的文本框,那么他们的android:layout_weight值可以同为:1,如果一行中有两个不等长的文本框,那么他们的android:layout_weight值分别为:1和2 ,那么第一个文本框将占据剩余空间的三分之二,第二个文本框将占剩余空间的三分之一,android:layout_weight遵循数值越小,重要度越高的原则;
效果图:

[img]http://dl2.iteye.com/upload/attachment/0085/6620/cb18425c-8e2b-3dd0-8aa1-1bb73aa60a2f.png[/img]


<!--
布局之一:线性布局 LinearLayout
横向布局:一行多列 纵向布局:一列多行
LinearLayout的属性:
android:background 设置整个布局画面的背景
android:orientation="horizontal" 子元素的排列队形,是横向排列还是纵向排列
android:gravity="bottom" 子元素在布局中的缺省(默认)对齐方式
android:padding 设置子元素的彼次连接,中间不留空白

子元素的属性:
android:layout_gravity 设置自身对象在父布局中的看齐方式,可以更新父布局对象给定的缺省的值
android:layout_weight 将父布局中剩余的尺寸按各兄弟元素的weight值比例进行填充;
-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>

</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值