2013-05-12 54 views
2

試圖在XML文件中,新的問題,一些變化解僱了:意外的命名空間前綴 「的xmlns」

她的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

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

</LinearLayout> 

遇到錯誤在

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

意外的命名空間前綴 「的xmlns」 爲標籤斷

+0

但是,如果這兩個命名空間是一樣的,你爲什麼要再次聲明? '的xmlns:android'和'的xmlns:Android的,兩者都是指同一個命名空間'HTTP:// schemas.android.com/APK/RES/android' – 2013-05-12 20:24:27

回答

4

不知道如果我在這裏幫助,但我只在我的情況下,一旦申報命名空間中的RelativeLayout

<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" > 

    <fragment class="com.blablabla.MyFragment" 
      android:id="@+id/fragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
</RelativeLayout> 

我不片段中再次聲明命名空間如上圖所示。據我所知道的唯一的命名空間已TE在父申報一次的ViewGroup

+0

是的,但它涉及相同的命名空間。 我不知道爲什麼,但我的靈魂消除錯誤。檢查 – krzakov 2013-05-12 20:43:51

+0

好吧,讓我知道這是否解決了您的問題。我很好奇,因爲我是百分之百肯定的。 – 2013-05-12 20:57:43

+0

該死的,它的工作原理,我不知道爲什麼。 – krzakov 2013-05-12 21:03:32

0

如果我不得不猜測,你很可能會遇到this bug in the build tools

+0

所以沒有辦法做到這一點 - 地圖和例如,在TextView中同樣的活動? – krzakov 2013-05-12 20:23:44

+0

如果有一個錯誤的地獄應用程序如何命名爲「運動追蹤運動跟蹤器」使用地圖和其他東西上相同的活動? – krzakov 2013-05-12 20:25:40

+3

@krzakov:「所以沒有辦法做到這一點 - 在同一個活動中映射和例如TextView?」 - 當然。不要使用'xmlns:map',而是使用Java設置值。 「如果在地獄應用程序中使用地圖和其他相同活動的應用程序命名爲」Endomondo體育追蹤器「,會有什麼問題?」 - 也許他們擁有較少褻瀆的開發者。 – CommonsWare 2013-05-12 20:30:56