Linear Layout

Linear Layout

linear layout是一种view group,它以一个单一的方向(垂直或者是水平)排列它所有的子控件,你可以用android:orientation属性来指定布局方向。
linear layout所有的子控件都是一个个的堆叠在上一个子控件之后,所以如果一个linearlayout的方向是垂直的,那么在每一行只能有一个子控件,不管该控件有多宽。

Layout Weight

linear layout 可以通过android:layout_weight属性给每一个子控件分配一个weight。这个属性确定了每个子控件应该占据多少的屏幕空间。最大可以占据整个父控件所有的空间。父控件中的空间以子控件中声明的weight值的比例分配给子控件。默认的weight值是0。
例如:当三个button控件中的两个控件都声明了weight为1,另一个button没有给weight值,那么这个没有给定weight值的button控件就不会扩展,只是占据规定的位置,这两个给定weight值的控件就会扩展到完全占据剩余的空间。如果此时没有给定weight值的那个控件给定weight值是2,那么这三个button就按照1:1:2的比例来瓜分真个布局空间。

Example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="match_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、付费专栏及课程。

余额充值