I have referred to this site for Layout Tricks.
Over there one attribute is declared as android:layout_weight="1"
.
So my confusion is regarding android:layout_weight:
- where is the exact use of android:layout_weight ?
- Where开发者_如何学运维 should we use android:layout_weight ?
From what I understand of layout_weight, the closest comparison I could find is when you pass some % in HTML for the width or height of your div. In our context, the weigth seems to refer to the % of width or heigth your widget should get for itself compared to its neighbours in a given ViewGroup
. You can find another exemple with more explanation here.
If you look the way they use it, it sticks exactly to the definition. They give a height of 0dip to keep the whole space free, and then uses equal weigths for the 2 widgets to make same th same height.
layout_weight is quite simply a priority to apply to a view class, the higher, the larger the control or group will be in proportion to it's mates inside that group. The default is 0, so a weight of 1 makes it twice as large as other default controls. No mystery.
精彩评论