【发布时间】:2016-10-24 00:05:07
【问题描述】:
我正在尝试在我的游戏中添加横幅广告。我能够在加载时显示广告,但问题是当我使 Adview 对象不可见时,它没有在后台加载。仅当 Adview 对象的可见性设置为不可见时才会加载广告,但对于我的游戏,我必须在退出屏幕上显示广告。
提前致谢
代码:
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");
}
}
});
}
【问题讨论】:
标签: android loading ads banner invisible