2

Admob バナーをゲームに組み込むのに苦労しています。ゲームに簡単に実装できると考えたので、simple-xml-2.6.2.jar ライブラリを使用しました。これで、パブリッシャー ID とテスト デバイスの正しいコードを含む 1 つのレイアウト ファイルができました。

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

ゲームはランドスケープ モードで実行され、広告を上部または下部にバナーとして表示するようにしたいのですが、表示されるテスト広告はなく、その理由についてのアイデアもありません. どんな助けでも大歓迎です!

4

3 に答える 3

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
于 2012-11-18T14:20:05.327 に答える
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);
于 2012-11-18T18:11:33.757 に答える
1

考えられるアイデアが 2 つあります。

  1. xml から「zzzzzzzzzz」を削除します。

また

  1. SDK 3.2 以降を使用していることを確認してください。最近、この方法で同様の問題を解決しました。
于 2012-11-18T13:59:26.283 に答える