Android LinearLayout fill-the-middle

Bostone picture Bostone · Aug 1, 2009 · Viewed 12.2k times · Source

I have a vertical, set height (300px) LinearLayout (LL) with 3 nested LLs. 1 and 3rd are set with android:layout_height="wrap_content" and the middle one with android:layout_height="fill_parent". To my dismay, 3rd LL gets pushed out with 2nd one filling parent layout right to the bottom. How do I achieve desired effect since I want potentially resize the outside container with the middle portion expanding and contracting to accommodate the change

Answer

Bostone picture Bostone · Aug 1, 2009

Turned out (Thanks Mark Murphy for the answer) that all I was looking for was to set middle row to

layout_height="0px" and layout_weight="1"

If, after all the wrap_content and fixed-sized items are allocated for along an axis (horizontal or vertical), there is still room on that axis left over, LinearLayout then allocates the remaining space to those widgets with specified weights, in proportion to the weight.