<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>
In code version 1 The height of button 1 is 5 times the button 2
In code version 2 the height of button 2 is 5 times the button 1
When 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.