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

♀尐吖头ヾ 提交于 2019-12-01 05:10:52

问题


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)


回答1:


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>  



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!