LinearLayout(线性布局)

LinearLayout(线性布局)Android六大布局之一,屏幕适配用的比较多的就是LinearLayoutweight(权重属性)

1. 简单用法归纳:
     
按比例划分水平方向:将涉及到的Viewandroid:width属性设置为0dp,然后设置为android
weight属性设置比例即可;类推,竖直方向,只需设android:height0dp,然后设weight属性即可。
2. 直接用wrap_content
  wrap_content比较简单,android:layout_weight赋值直接就按比例
3. match_parent需要计算
例如:
   <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
  
   
xmlns:tools="http://schemas.android.com/tools"
   
   
android:id="@+id/LinearLayout1"
   
   
android:layout_width="match_parent"
   
   
android:layout_height="match_parent"
>    
    
    <TextView
   
       
android:layout_weight="1"
   
       
android:layout_width="fill_parent"
   
       
android:layout_height="fill_parent"
   
       
android:text="one"
    
       
android:background="#98FB98"
   
     />
   
     <TextView
   
       
android:layout_weight="2"
   
       
android:layout_width="fill_parent"
   
       
android:layout_height="fill_parent"
   
       
android:text="two"
    
       
android:background="#FFFF00"
   
     />
   
     <TextView
   
       
android:layout_weight="3"
   
       
android:layout_width="fill_parent"
   
       
android:layout_height="fill_parent"
   
       
android:text="three"
    
       
android:background="#FF00FF"
   
     />
   
    
</LinearLayout>

 
我们可以发现,最终显示比例是2:1,而不是123
这里其实没那么简单的,还是需要我们计算的
step1
              个个都是fill_parent,但是屏幕只有一个,那么1- 3 = - 2 fill_parent 
step2依次比例是1/6,2/6,3/6

step3先到先得,先分给one,计算:1 - 2 * (1/6) = 2/3 fill_parent 
               接着到two,计算:1 - 2 * (2/6) = 1/3 fill_parent 
               最后到three计算1- 2 * (3/6) = 0 fill_parent
 step4所以最后的结果是:one占了两份,two占了一份,three什么都没有
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值