英文:
Problem with showing button over google maps android
问题
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_orange"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
</ImageView>
</com.google.android.gms.maps.MapView>
</RelativeLayout>
<details>
<summary>英文:</summary>
I'm using google maps in android. Trying to create a layout with google map and some other widgets on the screen like drawer icon. Here is my xml code.
The problem I'm facing is drawer icon is visible in xml design layout but when I run the application on device it is not visible.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_orange"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp">
</ImageView>
</com.google.android.gms.maps.MapView>
</RelativeLayout>
[![UI design][1]][1]
[1]: https://i.stack.imgur.com/n9D7Z.png
</details>
# 答案1
**得分**: 0
我曾经使用过地图,但没有用过Google地图,不过无论如何,你尝试过将ImageView放在RelativeLayout中而不是MapView内部吗?RelativeLayout专门用于此目的,因此其中的项可以重叠。不确定Google地图的MapView是否接受ImageView。
```xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_orange"
android:layout_margin="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
</ImageView>
</RelativeLayout>
另外,如果你想要它看起来就像上面的图像,我建议使用FloatingActionButton来替代ImageView。
英文:
I have worked with maps but not with google maps, anyway have you tried putting the imageview in the relative layout instead of inside the MapView? RelativeLayouts are made for that purpose, so items init can overlap. not sure if a google maps mapview will accet an Imageview
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_orange"
android:layout_margin="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
</ImageView>
</RelativeLayout>
plus if you want it to look just like the image above I would recommend using a FloatingActionButton in place of the imageview
专注分享java语言的经验与见解,让所有开发者获益!
评论