LineLayout学习

LinearLayout ,让所有的子元素在同一个方向,垂直或者水平。我们可以设置orientation,默认是

LinearLayout中的所有元素,都是一个挨着一个的,垂直方向,每行只能有一个,无论他们有多宽,即使很窄咯

水平方向,只有一行,高是最高的子元素加上padding吧。下面这句不懂,还是边界的吧?

A LinearLayout respects margins between childrenand the gravity (right, center, or left alignment) of each child. 

另外重要的一点,是它有一个layout_weight属性,这个属性很有意思,默认是0,就是这个view有多大就显示多大,但是一旦你

设置了weight,水平方向的,会按照weight百分比分配宽度,垂直方向来分配高度。

官网说,如果让每个view平分屏幕,水平的话,设置他们的width 0dp,所有的weight 1

 垂直的话,他们的height 0dp,所有的weight 为1 。  当然我们可以设置一个合适的比例,

默认weight是0,就是自己应该显示的大小,但是设置weight之后,宽或者高会按照比例暂满剩下的屏幕。

官方的demo:

<?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>





还有一个重要的属性是 android:gravity 就是里面的元素的对齐方式,当然我们可以

设置view的Layout_gravity ,让view在视图中的对齐方式。这个优先级高于总的。或者是几个的综合吧。


最后divider属性,有问题,没有试验好,分隔如何做?



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值