Monday, October 26, 2009

Layout trick: use layout_weight to strech the view to fill up the screen

My intent was to put a ListView in the top of the screen, 2 buttons in the bottom of the screen.
I hope the 2 buttons could stay put at the bottom, no matter whether List was too short to fill the space left, or too long to have to be scrolled.

The trick was to use layout_weight="1" for the ListView.

<linearlayout android="" layout_width="fill_parent" layout_height="fill_parent" orientation="vertical">
<listview id="@+id/lv_his_list" layout_width="fill_parent" layout_height="0dip" layout_weight="1" stackfrombottom="true" transcriptmode="normal" choicemode="singleChoice">

<tablelayout layout_width="fill_parent" layout_height="wrap_content" stretchcolumns="0,1">
<button style="" id="@+id/btn_his_list_modify" text="@string/modify_str">



Another testing of mine was for TableLayout, it also made sense.