0
我正在嘗試在我的遊戲中添加橫幅廣告。我可以在加載時顯示廣告,但問題是當我使Adview對象在後臺無法加載時無法加載。廣告僅在Adview對象的可見性設置爲「不可見」時才加載,但對於我的遊戲,我必須在退出屏幕上顯示廣告。可見性設置爲INVISIBLE時,不會加載橫幅廣告
在此先感謝
代碼:
public void initAds()
{
rect_layout = (FrameLayout) findViewById(R.id.rectangleView);
banner_layout = (LinearLayout) findViewById(R.id.bannerView);
banner_ad = new AdView(_activity);
banner_ad.setAdUnitId(BANNER_AD_ID);
banner_ad.setAdSize(AdSize.SMART_BANNER);
AdRequest adRequestBanner = new AdRequest.Builder().build();
banner_ad.loadAd(adRequestBanner);
banner_layout.addView(banner_ad);
rect_ad = new AdView(_activity);
rect_ad.setAdUnitId(RECTANGLE_AD_ID);
rect_ad.setAdSize(AdSize.MEDIUM_RECTANGLE);
AdRequest adRequestRectangle = new AdRequest.Builder().build();
rect_ad.loadAd(adRequestRectangle);
rect_layout.addView(rect_ad);
rect_ad.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
}
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
@Override
public void onAdOpened() {
super.onAdOpened();
}
@Override
public void onAdLoaded() {
super.onAdLoaded();
//rect_layout.setVisibility(View.INVISIBLE);
}
});
//rect_layout.setAlpha(0);
}
//Rectangular ad
public static void showRectangularAd(final String _show)
{
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if(Boolean.parseBoolean(_show))
{
_activity.rect_layout.setVisibility(View.VISIBLE);
//_activity.rect_layout.setAlpha(1);
Log.d(TAG, "Set to visible");
}
else
{
_activity.rect_layout.setVisibility(View.INVISIBLE);
//_activity.rect_layout.setAlpha(0);
Log.d(TAG, "Set to invisible");
}
}
});
}
好的 非常感謝您的回答,現在問題已經解決。 –
你是如何解決它的,分享你的問題的答案,並將其標記爲已回答。 @JaiSharma – HourGlass