2013-03-09 51 views
3

我已經在許多地圖的例子遇到這樣的代碼:令人費解的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> 

然而,對於所有這些,它去,我得到錯誤

意外描述資源路徑位置類型命名空間前綴 「的xmlns」 找到的標籤 片段activity_msmap.xml /示例/ RES /佈局線8的Android棉絨 問題

在行

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

所以......這到底是怎麼回事?我在任何地方都可以看到它,但是在我的Eclipse/Android中導致錯誤?另外,爲什麼在父元素中定義時重複相同的xml名稱空間?

回答

8

您不能在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" /> 
+0

感謝您的澄清:) – Tom 2013-03-09 10:25:29