android属性之Layout_weight

在android的布局文件中有一个属性:Layout_weight,直译为布局的重量级,即占布局中的重量比重,比如:

<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="9"/>
 <LinearLayout android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
	android:layout_weight="1"/>

这里layout02的layout_weight值为1,在android计算时,数字小的优先级高,这样就是layout02在申请占屏幕空间的时候,因为layout_width=fill_parent,填充父控件空间,所以就是占有的空间尽可能的大,两份空间,一份9/10,一份1/10,Layout02据有优先级,所以会占用9/10的空间。

如果android:layout_width="wrap_content"时候,情况就不一样了。

 <LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="9"	/>
 <LinearLayout android:id="@+id/LinearLayout02"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
	android:layout_weight="1"/>

layout02将占据总量1+9的1份空间,这是怎么回事呢?

这是因为当layout_width=wrap_content时,控件的大小是适应内容的宽度,意思是尽可能的小,所以layout02在挑选空间的时候,一份1/10,一份9/10,只有挑选1/10的空间了。

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值