Showing posts with label android layout layout_weight. Show all posts
Showing posts with label android layout layout_weight. Show all posts

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="http://schemas.android.com/apk/res/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">
<tablerow>
<button style="" id="@+id/btn_his_list_modify" text="@string/modify_str">

</button></tablerow>
</tablelayout>

</listview>

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