我很难将 Admob 横幅集成到我的游戏中。我使用了simple-xml-2.6.2.jar库,因为我认为它很容易实现到我的游戏中。现在我有一个布局文件,其中包含发布者 ID 和测试设备的正确代码:
<?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>
游戏以横向模式运行,我想让广告在顶部或底部显示为横幅,但没有显示任何测试广告,我没有任何想法为什么会这样。任何帮助都值得赞赏!
在 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
我有 2 个可能的想法给你:
- 从 xml 中删除"zzzzzzzzzz"。
或
- 确保您使用的是 SDK 3.2 或更高版本。我最近用这种方法解决了类似的问题。
试试这个:
<?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);