Admob与Android中的simple-xml集成?

时间:2012-11-18 13:55:09

标签: android admob integration simple-framework

我很难将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>

游戏以横向模式运行,我想让广告在顶部或底部显示为横幅,但没有显示任何测试广告,我也没有任何想法这是为什么。 任何帮助都是折旧的!

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

我有两个可能的想法:

  1. 从xml中删除“zzzzzzzzzz”。
    1. 确保您使用的是SDK 3.2或更高版本。我最近用这种方法解决了类似的问题。

答案 2 :(得分: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);