我在许多地图示例中遇到过这样的代码:
<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" />