Android: strange weight inversion in LinearLayout
android, android-linearlayout, android-view
Solution
Weight get inverse because you are using `match_parent` as the `layout_height`. The weight is used to distribute the remaining empty space or take away space when the total sum is larger than the `LinearLayout`. Set your heights to 0dip it will work.
i.e., set `layout_height = "0dip"` for both `ScrollView` and inner `LinearLayout`.
Reference :
The use of layout_weight with Android layouts
Problem
This is the xml layout i'm working on: ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF" android:orientation="vertical" > <ScrollView android:layout_weight="2" android:id="@+id/scrollConfirm" android:layout_width="fill_parent" android:layout_height="fill_parent"> </ScrollView> <LinearLayout android:layout_marginTop="20px" android:layout_weight="1" android:id="@+id/imageNumpad" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:src="@drawable/myicon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="#FFFFFF" /> </LinearLayout> </LinearLayout> ``` Since I have setted the ScrollView with `layout_weight="2"` and the LinearLayout (child) with `layout_weight="1"` I expected that the ScrollView will use up twice free space that the LinearLayout. But I obtain the opposite result. The ScrollView is smaller than LinearLayout. Whereas if I set for the ScrollView `layout_weight="1"` and LinearLayout with `layout_weight="2"`, the ScrollView is greater than LinearLayou. How is this possible??