Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place a RelativeLayout at the bottom of a RelativeLayout?

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)

like image 570
UpCat Avatar asked Aug 16 '10 11:08

UpCat


2 Answers

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> 
like image 102
Konstantin Burov Avatar answered Nov 15 '22 07:11

Konstantin Burov


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> 
like image 44
Janusz Avatar answered Nov 15 '22 07:11

Janusz