在Android中将按钮放置在地图顶部
我目前在我的Android应用程序中实现了一个地图,我在试图在上面放置一个按钮时遇到了一些麻烦 目前,它的显示方式如下: 我想防止按钮是透明的,理想情况下,我希望它如下所示,或者甚至让按钮跨越屏幕的宽度并粘贴到地图的顶部- 有人能告诉我如何在我的第二张截图中实现外观的正确方向吗?甚至在顶部有一个不透明的按钮,地图也不必在一个框架或任何东西中。这是我的代码,上面的截图-在Android中将按钮放置在地图顶部,android,xml,google-maps,Android,Xml,Google Maps,我目前在我的Android应用程序中实现了一个地图,我在试图在上面放置一个按钮时遇到了一些麻烦 目前,它的显示方式如下: 我想防止按钮是透明的,理想情况下,我希望它如下所示,或者甚至让按钮跨越屏幕的宽度并粘贴到地图的顶部- 有人能告诉我如何在我的第二张截图中实现外观的正确方向吗?甚至在顶部有一个不透明的按钮,地图也不必在一个框架或任何东西中。这是我的代码,上面的截图- <fragment xmlns:android="http://schemas.android.com/apk/res/a
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.example.pro.maps.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/btn_login"
android:layout_gravity="center_horizontal"/>
如果有人能帮助我,我将不胜感激。将两个视图嵌套在不同的布局中,如RelativeLayout。利用alignParentTop、align_bottom等属性
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/btn_login"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"/>
<fragment
android:layout_below="@+id/btn_login"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.example.pro.maps.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
谢谢你的建议,我已经尝试过了,但是我在..SupportMapFragment>部分旁边出现了一个错误,说“Element fragment未关闭”。如果我在最后加上“/>”,它会给我一个顶部线性布局的错误。非常感谢,这正是我要找的!