在Google地图Android上显示按钮的问题。

huangapple 未分类评论49阅读模式
标题翻译

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>

在Google地图Android上显示按钮的问题。


<details>
<summary>英文翻译</summary>

I&#39;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&#39;m facing is drawer icon is visible in xml design layout but when I run the application on device it is not visible.

    &lt;RelativeLayout
        xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
        xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
        xmlns:tools=&quot;http://schemas.android.com/tools&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        tools:context=&quot;.ui.home.HomeFragment&quot;&gt;
    
    
           &lt;com.google.android.gms.maps.MapView
            android:id=&quot;@+id/mapView&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            tools:ignore=&quot;MissingConstraints&quot; &gt;
               &lt;ImageView
                   android:layout_width=&quot;wrap_content&quot;
                   android:layout_height=&quot;wrap_content&quot;
                   android:src=&quot;@drawable/ic_menu_orange&quot;
                   android:layout_marginTop=&quot;20dp&quot;
                   android:layout_marginLeft=&quot;20dp&quot;&gt;
               &lt;/ImageView&gt;
           &lt;/com.google.android.gms.maps.MapView&gt;
    &lt;/RelativeLayout&gt;

[![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

&lt;RelativeLayout
xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
tools:context=&quot;.ui.home.HomeFragment&quot;&gt;


   &lt;com.google.android.gms.maps.MapView
    android:id=&quot;@+id/mapView&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    tools:ignore=&quot;MissingConstraints&quot; /&gt;
   

   &lt;ImageView
           android:layout_width=&quot;wrap_content&quot;
           android:layout_height=&quot;wrap_content&quot;
           android:src=&quot;@drawable/ic_menu_orange&quot;
           android:layout_margin=&quot;20dp&quot;
           android:layout_alignParentBottom=&quot;true&quot;
           android:layout_alignParentEnd=&quot;true&quot;&gt;
   &lt;/ImageView&gt;
&lt;/RelativeLayout&gt;

plus if you want it to look just like the image above I would recommend using a FloatingActionButton in place of the imageview

huangapple
  • 本文由 发表于 2020年3月16日 10:51:00
  • 转载请务必保留本文链接:https://java.coder-hub.com/60699769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定