Linear Layout(线性布局)

Linear Layout
    LinearLayout是一个排列子元素单一方向(横向或纵向)的view组。你可以通过android:orientation属性指定一个布局方向。

    LinearLayout的所有子元素一个接一个的堆放在一起,因此一个纵向列表只有一个任意宽度的列,一个横向的布局只有一行(他的高度取决于他最高的子元素的高的和填充部分的和)。LinearLayout的边距由他的子元素和每个子元素在该容器内的位置决定(中心、靠右、左对齐)。
    Layout Weight
    LinearLayout 也可以通过 android:layout_weight属性为他的子元素指定重要性,为这个属性分配一个重要性的值来决定一个元素在屏幕中占多大的空间。大的weight属性值可以使组件扩充多余的空间充满父组件。子元素可以分配一个Weight属性值,剩余的空间根据每个元素的Weight值来按比例分配给每个元素。默认的Weight是0。
   假如现在有三个TextView元素,其中两个的weight属性为“1”,另外一个没有指定weight属性,第三个元素是不能进行扩展的,他占有的空间需要根据他的内容而定。其他的两个元素将平分剩余的空间。如果指定第三个元素的weight为“2”,则他将占据总空间的一半,另外的两个元素平分剩余的空间。
Example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值