0

我遵循了有关如何添加广告的文档,但是我似乎遗漏了一些东西,因为示例应用程序正在运行。admob 帐户报告我的应用程序正在请求广告,我在 logcat 中看到了请求,但广告没有显示。

这是 onCreate 的代码:

this.adView = new AdView(this, AdSize.BANNER, MY_UNIT_ID);
LinearLayout layout = (LinearLayout) findViewById(R.id.appLayout);
layout.addView(adView);
AdRequest ad = new AdRequest();
ad.addTestDevice("DEVICE_ID");
this.adView.loadAd(ad);

这是我的布局:

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

   <ListView
       android:id="@+id/myListView"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:scrollbars="vertical" 
       >
   </ListView>
</LinearLayout>

在 AndroidManifest.XML 中:

我宣布了 2 个必需的权限:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

和活动:

<activity android:name="com.google.ads.AdActivity"                android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

我错过了什么?

编辑:我也附上了一个 logcat

05-26 21:04:01.761: I/Ads(6186): adRequestUrlHtml: removed requestHtml also
05-26 21:04:02.171: I/Ads(6186): Received ad url: removed ad url from here
05-26 21:04:02.752: I/Ads(6186): onReceiveAd()
4

2 回答 2

0

这是因为,您的视图不可见,您的 ListView 我们占用了所有空间。请更改它会起作用。

于 2012-05-26T17:58:04.667 回答
0

好吧,看来我也实现了 onResume()。如果您同时实现了 onCreate 和 onResume,则应该在那里完成整个广告加载。

于 2012-05-26T20:27:36.167 回答