2012-11-18 42 views
2

我很難將Admob橫幅集成到我的遊戲中。我使用了simple-xml-2.6.2.jar庫,因爲我認爲它很容易實現到我的遊戲中。現在我有一個佈局文件,與發佈者ID和測試設備的正確代碼:Admob與Android中的simple-xml集成?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
<com.google.ads.AdView android:id="@+id/adView" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        ads:adUnitId="xxxxxxxxxxx" 
        ads:adSize="BANNER" 
        ads:testDevices="TEST_EMULATOR, zzzzzzzzzzzz" 
        ads:loadAdOnCreate="true"/> 
</LinearLayout> 

遊戲在橫向模式下運行,並且我想恩獲得的廣告展示的一面旗幟在頂部或底部,但沒有顯示任何測試廣告,我對此沒有任何想法。 任何幫助是apreciated!

+0

檢查logcat的輸出。你看到了什麼樣的信息? –

回答

2

使用下面的代碼在XML中說XML名稱是adview.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/adView" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="50dip"/> 

現在,在您的活動加載廣告。

AdView adView = new AdView(this,AdSize.BANNER,"yourid"); 
LinearLayout ll= (LinearLayout) findViewById(R.id.adView); 
ll.addView(adView); 
AdRequest ar = new AdRequest(); 
ar.setGender(AdRequest.FEMALE); 
adView.loadAd(ar); 

您可以在您的任何活動的這一觀點(XML)的XML這樣的..

<include layout="@layout/adview" /> // your xml 
+0

我明白了,我認爲這會奏效。只要我回家,我會在你看到問題後將你的問題標記爲我接受的答案。非常感謝,會讓你更新。 – Flo

1

我對你有2點可能的想法:

  1. 刪除XML中的 「ZZZZZZZZZZ」。

  1. 確保您使用的SDK 3.2或以上。我最近用這種方法解決了類似的問題。
+0

我試過了,但不幸的是它沒有工作......謝謝你的回答。 – Flo

1

試試這個:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

    <com.google.ads.AdView 
     android:id="@+id/ad" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/admob_publisher_id" 
     ads:loadAdOnCreate="true" > 
    </com.google.ads.AdView> 

</RelativeLayout> 

AdView adView = (AdView) findViewById(R.id.ad); 
AdRequest adRequest = new AdRequest(); 
adView.loadAd(adRequest);