I have a RelativeLayout
, and this Layout has two childs, one is a MapView
and the other a RelativeLayout
that contains a button.
I want it to look like that
but my transparent box (a RelativeLayout
) is always displayed at the top of the map.
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.google.android.maps.MapView android:id="@+id/mapView"/> <test.project.TransparentPanel android:layout_width="fill_parent" android:layout_width="fill_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me!"/> </test.project.TransparentPanel> </RelativeLayout>
(i've left out some things in the code)
Try adding a alignParentBottom option to the transparent panel.
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.google.android.maps.MapView android:id="@+id/mapView"/> <test.project.TransparentPanel android:layout_width="fill_parent" android:layout_width="fill_parent" android:layout_alignParentBottom="true"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me!"/> </test.project.TransparentPanel> </RelativeLayout>
As Konstantin pointed out use layout_alignParentBottom
to position the button at the bottom of your view. The problem now is that the mapview will also stretch itself out to the bottom of the parent. Therefore the mapview will ´grow´ under the button until the parent is filled.
Try the following. First position the button at the bottom of the parent view, then align above the button.
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <test.project.TransparentPanel android:id="@+id/button_area" android:layout_width="fill_parent" android:layout_width="fill_parent" android:layout_alignParentBottom="true"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me!"/> </test.project.TransparentPanel> <com.google.android.maps.MapView android:id="@+id/mapView" layout_above="@id/button_area"/> </RelativeLayout>
来源:https://stackoverflow.com/questions/3492721/how-to-place-a-relativelayout-at-the-bottom-of-a-relativelayout