我在许多 map 示例中都遇到过这样的代码:
<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 布局中定义命名空间两次。 只需将它从您的 fragment 中删除,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 - 令人费解的Android xmlns错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15305778/