Android知识点随记

1.android:layout_weight

layout_weight属性指定剩余空间如何分配,指定了weight属性,把layout_width或者layout_height设为0dp,这样可避免不必要的计算,提高效率。

<EditText
    android:layout_weight="1"
    android:layout_width="0dp"
    ... />

The weight value is a number that specifies the amount of remaining space each view should consume,relative to the amount consumed by sibling views. This works kind of like theamount of ingredients in a drink recipe: "2parts soda, 1 part syrup" means two-thirds of the drink is soda. For example, if you giveone view a weight of 2 and another one a weight of 1, the sum is 3, so the first view fills 2/3 ofthe remaining space and the second view fills the rest. If you add a third view and give it a weightof 1, then the first view (with weight of 2) now gets 1/2 the remaining space, while the remainingtwo each get 1/4.

The default weight for all views is 0, so if you specify any weight valuegreater than 0 to only one view, then that view fills whatever space remains after all views aregiven the space they require.

Setting the width to zero improves layout performance because using"wrap_content" as the width requires the system to calculate a width that is ultimately irrelevant(最终不相关的) because the weight value requires another width calculation to fill theremaining space.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值