【问题标题】:Android Studio: xmlns:map not workingAndroid Studio: xmlns:map 不工作
【发布时间】:2013-06-04 05:20:36
【问题描述】:

经过大量研究,但没有找到任何东西...快速提问,有人知道为什么 Android Studio 不使用 Map 标签吗?下面的代码是 SDK 中地图示例的片段。已经添加了 google play services 库和支持,但没有。

显示错误

Unexpected namespace prefix "map" found for tag fragment.

提前非常感谢!

<fragment
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    map:cameraZoom="10" />

【问题讨论】:

  • 听起来很像这个 Eclipse 错误:code.google.com/p/android/issues/detail?id=53283
  • 所以似乎唯一的解决方案是在 java 代码而不是 xml 文件上执行此操作,对吗?谢谢你!
  • 是的,AFAIK 实现此功能的唯一可靠方法是通过 Java 代码。这是一个错误,希望有一天会得到修复......
  • 问题是它在 Eclipse 上运行良好,我只需添加对 google play 服务的引用就可以了,但 Android Studio 没有。再次感谢 CommonsWare!
  • Android Studio 1.4 仍然存在这个问题。显示 Xml 错误,但工作正常。只需忽略这一点。

标签: android android-layout android-xml android-studio


【解决方案1】:

将地图片段移动到 FrameLayout 后,我​​遇到了同样的问题(因此我可以在地图顶部添加一个按钮)。

我不知道我到底做了什么,因为我是 Android 应用程序和 XML 的菜鸟,但看起来我找到了解决方案 :-)

我尝试使用包含来自单独文件的片段的技巧(使用“包含”指令),一旦我放置了没有任何命名空间定义的裸地图片段,它就向我提出了 2 个选项: xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/tools" 我意识到也许第二个可以在原始文件中工作(虽然在原始文件中 Android Studio 没有提出它,但只有第一个)。

结论: 只需更改此行: xmlns:map="http://schemas.android.com/apk/res-auto" 有了这个: xmlns:map="http://schemas.android.com/tools"

正如我所提到的 - 我是个菜鸟,也许我的解决方案有一些副作用,所以请告诉我(尽管到目前为止一切似乎都运行良好......)。

这是我的工作地图布局,顶部有一个按钮,没有错误:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
             
    xmlns:map="http://schemas.android.com/tools"
             
  tools:context="com.maverickrider.myapp.inviteActivity.MapsActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purpura_E51B4A">

<fragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"

    map:cameraTargetLat="51.513259"
    map:cameraTargetLng="-0.129147"
    map:cameraTilt="30"
    map:cameraZoom="13"
    />

<Button
    android:id="@+id/startActivityButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|center_vertical"
    android:onClick="cokolwiek"
    android:text="Baton z dupy"
    android:layout_alignParentBottom="true"
    />

</FrameLayout > 

【讨论】:

  • 这只是名称为“map”的“tools”命名空间。不一样。
【解决方案2】:

我也有这个问题。我做了项目/清理,错误消失了,现在工作正常。这假定地图命名空间已在上面使用它的位置正确定义。

【讨论】:

    【解决方案3】:

    我正在运行 0.5.8,并且 XML 查看器正在使用 map 为 attrs 下划线: - 但是该应用程序正在构建良好。 YMMMV。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-06
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 2021-03-18
      相关资源
      最近更新 更多