android:layout_weight
Notice that all the layout_height properties are set to 0dp. Effectively the layout_weight is replacing the layout_height property. The context in which we use layout_weight is important (or it won't work) and we will see this in a real project soon. Also note that we don't have to use fractions of 1, we can use whole numbers, percentages, and any other number, and as long as they are relative to each other they will probably achieve the effect you are after. Note that layout_weight only works in certain contexts and we will get to see where when we build some layouts [Ref 1].
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:text="one tenth" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"
android:text="two tenths" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".3"
android:text="three tenths" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
android:text="four tenths" />
android:layout_weight |
Copyright ©2017, Software Developer, All rights reserved.
See Contents
No comments:
Post a Comment