How to make layout with View fill the remaining space?
Answer from woodshy worked for me, and it is simpler than the answer by Ungureanu Liviu since it does not use RelativeLayout
.I am giving my layout for clarity:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width = "80dp" android:layout_weight = "0" android:layout_height = "wrap_content" android:text="<"/> <TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:layout_weight = "1"/> <Button android:layout_width = "80dp" android:layout_weight = "0" android:layout_height = "wrap_content" android:text=">"/> </LinearLayout>
In case if < TEXT VIEW > is placed in LinearLayout, set the Layout_weight proprty of < and > to 0 and 1 for TextView.
In case of RelativeLayout align < and > to left and right and set "Layout to left of" and "Layout to right of" property of TextView to ids of < and >
If you use RelativeLayout
, you can do it something like this:
<RelativeLayout android:layout_width = "fill_parent" android:layout_height = "fill_parent"> <ImageView android:id = "@+id/my_image" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_alignParentTop ="true" /> <RelativeLayout android:id="@+id/layout_bottom" android:layout_width="fill_parent" android:layout_height = "50dp" android:layout_alignParentBottom = "true"> <Button android:id = "@+id/but_left" android:layout_width = "80dp" android:layout_height = "wrap_content" android:text="<" android:layout_alignParentLeft = "true"/> <TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:layout_toLeftOf = "@+id/but_right" android:layout_toRightOf = "@id/but_left" /> <Button android:id = "@id/but_right" android:layout_width = "80dp" android:layout_height = "wrap_content" android:text=">" android:layout_alignParentRight = "true"/> </RelativeLayout></RelativeLayout>