如何将Relativelayout放置在Relativelayout的底部?
-
28-09-2019 - |
题
我有一个 RelativeLayout
, ,这个布局有两个孩子,一个是 MapView
还有另一个 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>
(我在代码中遗漏了一些东西)
解决方案
尝试在透明面板中添加一个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>
其他提示
正如Konstantin指出的那样 layout_alignParentBottom
将按钮放在视图底部。现在的问题是,MapView还将伸展到父母的底部。因此,MapView将在按钮下“ Groww”,直到填充父为止。
尝试以下内容。首先将按钮放在父视图的底部,然后对准按钮上方。
<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>
不隶属于 StackOverflow