android:layout_weight unexpected behaviour?

RadiantThunder

New Member
\[code\]<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="5" android:text="Button1" android:textSize="20dp" > </Button> <Button android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="Button2" android:textSize="20dp" > </Button></LinearLayout><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="5" android:text="Button1" android:textSize="20dp" > </Button> <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Button2" android:textSize="20dp" > </Button></LinearLayout>\[/code\]In code version 1The height of button 1 is 5 times the button 2In code version 2the height of button 2 is 5 times the button 1When android:layout_height="0dp" is replaced with android:layout_height="match_patent" the weights are reversed.Can you explain this behavior and how android:layout_weights actually works and explain the reason in each case.
 
Back
Top