2014-09-28 109 views
0

我的activity_main.xml佈局文件指出一個錯誤:解析XML時出錯:未綁定的前綴。不知道爲什麼 - 它似乎與AdView有關。爲什麼我的android佈局XML中存在解析錯誤?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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" 
    android:orientation="horizontal"> 


<-- ERROR HERE - error parsing XML: unbound prefix --> 
    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         ads:adUnitId="ca-app-pub-xxxxxx/xxxxxx" 
         ads:adSize="SMART_BANNER"/>  

</LinearLayout> 

回答

3

你忘了定義自定義屬性(adSize & adUnitId)的ads前綴。

添加到LinearLayout容器:

xmlns:ads="http://schemas.android.com/apk/res-auto" 

更多細節here

+0

我以前實際上使用這個沒有成功。但你的作品。不知道這是從xmlns來的:googleads =「http://schemas.android.com/apk/res-auto」 – glutz 2014-09-28 00:37:44

+0

@glutz:那也可以,但是你必須使用'googleads'前綴在這種情況下具有屬性;即'googleads:adSize'。事實上,只要你一致,你可以給它任何你喜歡的名字。 – 2014-09-28 06:12:15

+0

@glutz:請不要忘記接受答案,以便其他人也可以從中受益! – 2014-10-05 08:52:45

0

你可能已經忘記了添加這個

xmlns:ads="http://schemas.android.com/apk/res-auto" 

你是否也包含正確的庫?