2010-08-16 381 views
2

我有一个RelativeLayout,这个布局有两个孩子,一个是MapView,另一个是RelativeLayout,它包含一个按钮。如何将RelativeLayout放置在RelativeLayout的底部?

我希望它看起来像

但我的透明包装盒(一RelativeLayout)总是在地图上显示出来。

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

(我已经离开了在代码中的一些东西)

回答

6

尝试添加alignParentBottom选项透明面板。

<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

Konstantin指出使用layout_alignParentBottom将按钮放置在视图的底部。现在的问题是,mapview也会伸展到父级的底部。因此,mapview将在按钮下方“放大”,直到父项被填充。

请尝试以下操作。首先将按钮放在父视图的底部,然后对齐按钮上方。

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