Admob android无法从横幅INVISIBLE更改为VISIBLE

时间:2015-09-05 09:12:15

标签: android admob

你们如何使用admob横幅?你能看看我的代码,并说明它有什么问题。我有一个具有暂停屏幕的游戏,它有很大的空间放置横幅。

然而,当我加载它时,横幅需要很长时间才能显示缓慢连接。所以我做了加载,但保持不可见,然后在需要时让它可见。但它不起作用。横幅将不可见!请给我任何建议...... 这是代码:

//Admob request Banner
bannerAdmob = new AdView(this);
bannerAdmob.setAdSize(AdSize.WIDE_SKYSCRAPER);
bannerAdmob.setAdUnitId(Setting.admobBannerId);
requestAdmobBanner();

我使用处理程序来选择adunit。非页内广告很好用,但不是横幅广告。

protected Handler handlerAdmob = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case 1: //If is interstitial
            if (interstitialAdmob.isLoaded()) {
                interstitialAdmob.show();
            } else {                        
                requestAdmobInterstitial();
            }
            break;
        case 2: //If is banner
            bannerAdmob.setVisibility(View.VISIBLE);
            break;
        case 6: //Hide banner
            bannerAdmob.destroy();
            requestAdmobBanner(); //Request new banner
        }
    }
};

然后加载横幅的方法

private void requestAdmobBanner() {
    AdRequest bannerRequest = new AdRequest.Builder()
    // Add a test device to show Test Ads
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice(Setting.Device_ID)
    .build();

    // Load the banner ad.
    bannerAdmob.loadAd(bannerRequest);

    // Now we add ads listener for Admob banner so we can SHOW and HIDE it
    bannerAdmob.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) { // On admob interstitial failed to load, request new ad
            bannerAdmob.setVisibility(View.GONE);
        }

        @Override
        public void onAdLoaded() {
            bannerAdmob.setVisibility(View.INVISIBLE);
            System.out.println("Banner Admob is load, but still INVISIBLE");
        }
    });
}

1 个答案:

答案 0 :(得分:1)

当您将AdView设置为 VISIBLE 时,您将AdView设置为 INVISIBLE 。请参阅以下代码:

// Now we add ads listener for Admob banner so we can SHOW and HIDE it
bannerAdmob.setAdListener(new AdListener() {
    @Override
    public void onAdFailedToLoad(int errorCode) { // On admob interstitial failed to load, request new ad
        bannerAdmob.setVisibility(View.GONE);
    }

    @Override
    public void onAdLoaded() {
        bannerAdmob.setVisibility(View.VISIBLE);
        System.out.println("#onAdLoaded - making AdView visible");
    }
});