令人费解的Android xmlns错误

我在许多地图示例中遇到过这样的代码:

<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"
    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"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

然而,对于他们所有人来说,我得到了错误

Description Resource Path Location Type Unexpected namespace prefix
“xmlns” found for tag
fragment activity_msmap.xml /example/res/layout line 8 Android Lint
Problem

在线

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

那么……这里发生了什么?我在各地的例子中看到它,但它导致我的Eclipse / Android出错?另外,为什么在父元素中也定义了同样的xml命名空间?

解决方法:

您无法在xml布局中两次定义命名空间.
只需从片段中删除它,RelativeLayout已经定义了xmlns:android命名空间.

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

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...