Unexpected namespace “map” - Android Google Maps API

橙三吉。 提交于 2020-01-11 11:38:08

问题


Here's the entirity of my XML file. The imporant part is the map fragment at the end that gives me this error: "Unexpected namespace prefix found for tag fragment" It doesn't seem to impact the code but I'm curious if anyone knows what's up. I've seen posts saying it's a Lint issue or an Eclipse problem but I'm using the latest version of Android Studio.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              xmlns:map="http://schemas.android.com/apk/res-auto"
              android:background="#FFFFFF"
              android:orientation="vertical">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button_lakeside_webview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lakeside"/>

        <Button
            android:id="@+id/button_spinner_webview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Spinner"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/colored_bar"
            android:layout_width="48dp"
            android:layout_height="3dp"
            android:background="" />

    </LinearLayout>

    <!-- Unsure why it complains about the map namespace, the below code is recommended by Google -->

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:map="http://schemas.android.com/apk/res-auto"
              android:name="com.google.android.gms.maps.SupportMapFragment"
              android:id="@+id/map"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              map:cameraBearing="0"
              map:cameraTilt="30"
              map:cameraZoom="16"
              map:mapType="normal"
              map:uiCompass="false"
              map:uiRotateGestures="false"
              map:uiScrollGestures="false"
              map:uiTiltGestures="false"
              map:uiZoomControls="false"
              map:uiZoomGestures="false"/>

</LinearLayout>

回答1:


As you say there is a known bug in the Android Lint. There are a couple of issues filed:

  • Issue 5002: Bug: Options can't be set on MapFragments included in other layouts
  • Issue 159039: Custom XML attributes doesn't work on tag in layout XMLs
  • Issue 53283: Library project namespace only working on root element

The last one updated on Jul 14 2016 states that "Please try again on a newer version of Android Studio (2.2 or greater). If the issue still occurs file a new bug."

As a workaround you can add this property to the fragment to ignore the error (I have tested it and the map:properties work as expected):

tools:ignore="MissingPrefix"


来源:https://stackoverflow.com/questions/38465977/unexpected-namespace-map-android-google-maps-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!