height worked out dynamically at rendering time
I have to make a simple layout in android but have problem with the heigh of the central element. basically I have a header, a body and 开发者_如何转开发a footer. header and footer have fixed height but I'd like the body to fill the remaining space. this should be screen size independent so I'd like the height of the body to be dynamically worked out when the layout is being rendered.
do you guyz know how I can achieve the result?
thanks
Use a linear layout with a height of fill_parent; set the center element to have a height of 0px and a layout_weight of 1; set the header/footer to wrap_content or give them a fixed height.
Basically, after fixed-height (or width, in the case of a horizontal LinearLayout) elements are allocated, the remaining space is divided proportionally by weight among the remaining children with weights assigned to them.
Did you tried FILL_PARENT
?
FILL_PARENT, which means the view wants to be as big as its parent (minus padding)
Check this link.
use a RelativeLayout as the root. For the footer set android:layout_alignParentBottom="true"
in the xml and for the header set android:layout_alignParentTop="true"
then set the middle to fill_parent
and layout_above = your_footer
as well as layout_below = your_header
精彩评论