2014-03-30 32 views
2

我試圖放置帶有橫幅廣告的LinearLayout - 位於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" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".AllJokes" > 

    <ListView 
       android:id="@+id/allJokesList" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent"> 
    </ListView> 

    <LinearLayout 
      android:layout_alignParentBottom="true" 
      android:id="@+id/adViewContainer" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <com.google.android.gms.ads.AdView android:id="@+id/adView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         ads:adUnitId="MY_AD_UNIT_ID" 
         ads:adSize="BANNER"/> 
    </LinearLayout> 

</RelativeLayout> 

但它總是給我這個錯誤:

error: Error parsing XML: unbound prefix 

我知道我的格式是完全搞砸了,但我不能找到一種方法使其有效。

我只是需要一個線索,因爲我是一個在android和xml的初學者。我錯過了我知道的很小的東西。

回答

2

您必須XML佈局

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

!因爲你

ads:adUnitId="MY_AD_UNIT_ID" // see this attribute 
+0

謝謝你的幫助!:) – chility

+1

不客氣 – Raghunandan

1

您錯過了LinearLayout的尾部'>'。所以這部分應該是:

<LinearLayout 
    android:layout_alignParentBottom="true" 
    android:id="@+id/adViewContainer" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
+0

的根元素的下面我剛剛編輯了代碼和錯誤。 :( – chility