2010-08-16 18 views
2

J'ai un RelativeLayout, et cette mise en page a deux enfants, l'un est un MapView et l'autre un RelativeLayout qui contient un bouton.Comment placer un RelativeLayout en bas d'un RelativeLayout?

Je veux que ça ressemble à ce que

mais ma boîte transparente (un RelativeLayout) est toujours affiché en haut de la carte.

<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> 

(j'ai omis certaines choses dans le code)

Répondre

6

Essayez d'ajouter une option alignParentBottom au panneau transparent.

<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> 
2

Comme Konstantin a souligné l'utilisation layout_alignParentBottom pour positionner le bouton en bas de votre point de vue. Le problème est maintenant que mapview s'étendra aussi au fond du parent. Par conséquent, le mapview va «croître» sous le bouton jusqu'à ce que le parent soit rempli.

Essayez les solutions suivantes. Positionnez d'abord le bouton en bas de la vue parent, puis alignez-le au-dessus du bouton.

<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>