问题描述
我想补充之上的自定义按钮(的GoogleMap ,虽然我不知道那是多么有关...)片段。
I am trying to add a custom button on top of a (GoogleMap though I'm not sure how relevant that is...) fragment.
我不希望它坐它本身之下 - 就像我可以做的的FrameLayout 或的LinearLayout 的 - 但我想按钮,坐在上面与其父布局是透明的地图...
I don't want it to sit underneath it per se - like I could do with a FrameLayout or LinearLayout - but I want to the button to sit on top of the map with its parent layout being transparent...
这就是我(目前)在我的XML:
This is what I (currently) have in my xml:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:mapType="normal"
tools:layout="@layout/activity_location">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" // THIS DOESNT WORK !!!
android:background="#FC0" // for debug purposes
android:gravity="center|bottom" >
<Button
android:id="@+id/location_order_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/small_margin"
android:background="@drawable/nav_btn_send"
android:text=""
android:textColor="@color/black"
android:textSize="@dimen/loginFontSize" />
</RelativeLayout>
</fragment>
请注意上的评论机器人:layout_alignParentBottom和安卓背景'行...
Note the comments on the 'android:layout_alignParentBottom' and 'android:background' lines...
这给了我这样的结果:
现在...你可以通过code,我试图调整这一屏幕/图底部告诉...但无论我做什么,这是调整的顶部,下面的ActionBar ...
Now... you can tell through the code that I am attempting to align this to the screen/map bottom... but whatever I do, it is aligning to the top, underneath the ActionBar...
我都试过,我发现这么几个其他的方法,但这是最接近的结果我想到目前为止...
I have tried a few other approaches that I found on SO, but this is the closest result to what I want so far...
任何想法,我做错了?
推荐答案
您应该这样定义在 RelativeLayout的
您的片段:
You should define your fragment inside RelativeLayout
in this way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FC0"
android:gravity="center|bottom" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:mapType="normal"
tools:layout="@layout/activity_location" />
<Button
android:id="@+id/location_order_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/small_margin"
android:background="@drawable/nav_btn_send"
android:text=""
android:layout_alignParentBottom="true"
android:textColor="@color/black"
android:textSize="@dimen/loginFontSize" />
</RelativeLayout>
和你应该使用 layout_alignParentBottom
的子元素,你想在父母的底部对齐,在这种情况下的财产,这是按钮
and you should use layout_alignParentBottom
property in the child element that you want to align at the bottom of the parent, in this case, it is Button
这篇关于Android的 - 不能得到相对布局对齐父底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!