【问题标题】:Admob integration with simple-xml in Android?Admob 与 Android 中的 simple-xml 集成?
【发布时间】:2012-11-06 14:35:03
【问题描述】:

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

游戏以横向模式运行,我希望您将广告显示为顶部或底部的横幅,但没有显示任何测试广告,我没有任何想法这是为什么。 任何帮助都将不胜感激!

【问题讨论】:

  • 检查 logcat 输出。你看到什么样的消息?

标签: android admob integration simple-framework


【解决方案1】:

我有 2 个可能的想法给你:

  1. 从 xml 中删除“zzzzzzzzzz”。

或

  1. 确保您使用的是 SDK 3.2 或更高版本。我最近用这种方法解决了一个类似的问题。

【讨论】:

  • 我试过了,但不幸的是它没有用...感谢您的回答。
【解决方案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"/>

现在在您的 Activity 中加载广告。

 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

【讨论】:

  • 我明白了,我认为这会奏效。回到家后,我会在检查后将您的问题标记为我接受的答案。非常感谢,会及时更新。
【解决方案3】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    相关资源
    最近更新 更多