我尝试在方向更改时手动重新加载AdView。我能够发出请求并获得加回。问题是,当我尝试删除旧视图并添加新视图时,我收到此警告:
W/Ads: Not enough space to show ad. Needs 592x32 dp, but only has 640x0 dp.
视图未显示。这是我的onConfigurationChanged
方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.v(TAG, "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
ViewGroup.LayoutParams adViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adViewParent.removeView(adView);
adView.destroy();
AdView newAdView = new AdView(this);
newAdView.setAdSize(AdSize.SMART_BANNER);
newAdView.setAdUnitId(getString(R.string.admob_ad_unit_id_main));
newAdView.setLayoutParams(adViewParams);
newAdView.setId(R.id.adView);
adView = newAdView;
adViewParent.addView(adView);
loadAd();
}
我已经读过像android admob resize on landscape这样的其他类似答案,但它们对我不起作用,而且我真的不知道自己做错了什么。
感谢您的帮助。
答案 0 :(得分:0)
我希望它可以帮到你:
ViewGroup.LayoutParams adViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.dpToPx(32));
如果加载广告失败,请隐藏adViewParent.setVisibility(GONE)