【问题标题】:Xml attributes on Android Google Maps doesn't work with AndroidStudioAndroid Google Maps 上的 Xml 属性不适用于 Android Studio
【发布时间】:2013-09-11 08:47:57
【问题描述】:

我正在使用 Google 地图创建一个简单的 Android 应用。 我有这个布局:

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/root"
android:background="@android:color/transparent">

<fragment
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:name="com.google.android.gms.maps.MapFragment"
    android:id="@+id/map2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
     map:cameraBearing="112.5"
    map:cameraTargetLat="45.438122"
    map:cameraTargetLng="12.318221"
    map:cameraTilt="30"
    map:cameraZoom="18"
    map:mapType="normal"
    map:uiCompass="false"
    map:uiRotateGestures="true"
    map:uiScrollGestures="true"
    map:uiTiltGestures="false"
    map:uiZoomControls="true"
    map:uiZoomGestures="true"
    />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/map"
    android:layout_gravity="left|top"
    android:layout_alignParentLeft="false"
    android:layout_alignParentTop="false"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" />
 </FrameLayout>

AndroidStudio 告诉我:

Unexpected namespace prefix "map" found for tag fragment

如果代码对我来说还可以,它也会将所有带有“map”前缀的行标记为错误。 事实上,在部署我的应用程序时,我可以看到所有地图标签都在我的 Android 设备上运行。

所以我问这是否只是AndroidStudio的一个小错误。

有点好奇:改用这个布局 AndroidStudio 不会标记任何错误:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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:cameraBearing="112.5"
map:cameraTargetLat="45.438122"
map:cameraTargetLng="12.318221"
map:cameraTilt="30"
map:cameraZoom="18"
map:mapType="normal"
map:uiCompass="false"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiTiltGestures="false"
map:uiZoomControls="true"
map:uiZoomGestures="true"
/>

【问题讨论】:

  • 你的 build.gradle 中有 compile 'com.google.android.gms:play-services:3.2.25' 吗?
  • 当然。我再说一遍,该应用程序运行良好,没有问题。在我看来,这只是 Android Studio 的一个问题。

标签: android google-maps android-studio


【解决方案1】:

您的&lt;FrameLayout&gt; 元素中的xmlns:map="http://schemas.android.com/apk/res-auto" 命名空间声明似乎没有向下传递到&lt;fragment&gt; 命名空间。您的第二个示例在使用它的元素中具有命名空间声明 (&lt;fragment&gt;),Android Studio 会立即识别它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2014-10-12
    • 2014-03-28
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多