I am trying to build an android layout using layout_weight to fit all device sizes, and I have some problems understanding its correspondence.
I noticed that changing layout_width / layout_height affected layout_weight , but I don't understand how to do this.
Say, for example, I want to have a vertical LinearLayout divided by three inches LinearLayout , such as the upper and lower parts fill 25% of the screen, and in the middle 50%, and this should not depend on the contents of the internal layouts. (If the contents of the inner LinearLayout too large, it should not offset other layouts)
To do this, should I set the layout_height attribute of the inner LinearLayout to fill_parent or to wrap_content ?
Thanks!
EDIT: It looks like layout_weight is inversely proportional to the size of the layout that will occupy.
3 examples:
Weight 1/1/1 (works as I expected)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#FF0000"/> //RED <LinearLayout android:id="@+id/layout2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#00FF00"/> //GREEN <LinearLayout android:id="@+id/layout3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#0000FF"/> //BLUE </LinearLayout>
Results: 
Weight 1/2/1 (Why, oh why?)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#FF0000"/> //RED <LinearLayout android:id="@+id/layout2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:background="#00FF00"/> //GREEN <LinearLayout android:id="@+id/layout3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#0000FF"/> //BLUE </LinearLayout>
Results: 
** Weight 3/2/3 (What I wanted to do with 1/2/1):
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="3" android:background="#FF0000"/> //RED <LinearLayout android:id="@+id/layout2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:background="#00FF00"/> //GREEN <LinearLayout android:id="@+id/layout3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="3" android:background="#0000FF"/> //BLUE </LinearLayout>
Results: 