如何在Android的底部放置admob广告,而不使用布局xml

时间:2011-06-09 18:14:45

标签: layout admob

我想在我的apk底部放置一个admob广告,但广告从未显示过,而且我的apk中没有布局xml,布局是由游戏视图类构建的,

LogCat说:onFailedToReceiveAd(广告请求成功,但由于广告资源不足而没有返回广告)

这是我的代码

gameView = new GameView(this, display.getWidth(), display.getHeight());             
    setContentView(gameView);


    RelativeLayout viewLayout = new RelativeLayout(GameActivity.this);      
    RelativeLayout.LayoutParams flLP2 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    // Create the adView
    AdView adView = new AdView(this, AdSize.BANNER, "xxxxxx");     
    // Add the adView to it     
    viewLayout.addView(adView,flLP2);
    // Initiate a generic request to load it with an ad
    AdRequest adTest = new AdRequest();
    adTest.addTestDevice("xxxxxxxxxx");
    adView.loadAd(adTest);

1 个答案:

答案 0 :(得分:-1)

您使用的是正确的测试设备ID吗?检查logcat日志(标签“Ads”),应该有一行说:

Ads: To get test ads on this device, call adRequest.addTestDevice("xyz");