android - 应用程序不接受 xml 文件中的 gmap

标签 android xml

我正在开发基于 gmap 的应用程序。

为此,我正在关注 this文档。

它给我以下代码的 mainactivity.xml 错误:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

</RelativeLayout>

错误行:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"

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

错误文本:

Description Resource    Path    Location    Type
Unexpected namespace prefix "xmlns" found for tag fragment  activity_main.xml   /gmapAPP/res/layout line 14 Android Lint Problem
The processing instruction target matching "[xX][mM][lL]" is not allowed.   activity_main.xml   /gmapAPP/res/layout line 1  Android XML Format Problem

我的 list 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.gmapapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />


    <uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <uses-library android:name="com.google.android.maps"/>

        <activity
            android:name="com.example.gmapapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="your_apikey" />

    </application>

</manifest>

请帮帮我。

最佳答案

在最后一行尝试使用此 SupportMapFragment 而不是 MapFragment 也可以查看您的 fragment 标签。

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

<RelativeLayout 
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >


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

</RelativeLayout>

引用这个Example

关于android - 应用程序不接受 xml 文件中的 gmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18636326/

相关文章:

android - 错误 :The prefix "android" for attribute "android:versionCode" associated with an element type "manifest" is not bound

C# xml 验证

Android 使用 GSON 响应更新 SQLite ...我应该如何解析嵌套的 JSON?

android - 如何在线性布局中居中内容?

底部固定按钮的Android布局

android - @SmallTest、@MediumTest 和 @LargeTest 在 Android 上已弃用

android - 使用 Paypal Api 开发应用程序是否需要拥有 Paypal 商户帐户?

java - 以字符串形式访问 xml 中的数据

xml - 如何处理 Oracle XML DB native Web 服务中的 NULL 存储过程返回参数?

java - JAXB - 在编码为 XML 时,类包含可以展平吗?