LinearLayout中的layout_weight的使用


概述: android开发过程中我们会经常通过layout_weight来进行布局,这样做的好处就是可以多屏幕的适配。

LinearLayout中的layout_weight的使用在水平布局上和在垂直布局上都是一样的。所以我们就以水平布局上为例。


一、案例1


    

在水平布局上,显示两个View,我们知道如果不用weight属性的话,当我们把View1的weight设置为match_parent的时候,View2就会被挤到外面,从而看不到View2,。

那么我们为了 显示View2呢,就应用weight属性来满足我们的需求了。当View2 显示完整了,再把剩余的空间给View1,让View1,充满屏幕。


代码如下:

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


        <com.wubaiwan.wewin.widget.EditTextWithDel
            android:id="@+id/edtVerificationCode"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableLeft="@drawable/icon_password" >
        </com.wubaiwan.wewin.widget.EditTextWithDel>


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:text="@string/action_get_veri_code" />
    </LinearLayout>

 View1 充满屏幕,View2 包裹,这时候给View1加上更高的权重的话,那么就会得到我们想要的结果。


未完.......



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值