Admob广告未在屏幕方向上正确resize

我在我的应用中使用Admob广告,但我遇到了问题。 每当我将屏幕转为横向模式时,广告就会显示,但它与纵向模式下的尺寸相同。 在我的清单中将此xml声明添加到我的主要活动之后出现此问题,这是保持应用程序主要部分顺利运行所必需的:

android:configChanges="orientation|keyboardHidden|screenSize" 

我在广告中使用智能横幅尺寸:

 ads:adSize="SMART_BANNER" 

我附上了这个问题的图片:

这是肖像模式下的样子。它完美运行这是我侧翻手机后的样子。广告仍会显示,但不会调整为填充宽度

我必须做些什么才能让广告在横向模式下正确resize而不删除

 android:configChanges="orientation|keyboardHidden|screenSize" 

在我的主要活动的清单?

这就是我解决它的方式:

 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); orientation_changed = true; renewAd(); } private void renewAd() { AdView ad = (AdView) findViewById(R.id.adView); LayoutParams lp = (LayoutParams) ad.getLayoutParams(); // change relative layout for your layout which contains the adView RelativeLayout parent = (RelativeLayout) ad.getParent(); parent.removeView(ad); AdView newAd = new AdView(this, AdSize.SMART_BANNER, "YOUR ID"); newAd.setId(R.id.adView); newAd.setLayoutParams(lp); parent.addView(newAd); newAd.loadAd(new AdRequest()); } 

问候

与其他响应一致(但将其更新为当前的AdMob SDK -v7.5-并提供完整代码),活动的onConfigurationChanged()方法需要包括销毁和创建广告视图:

 // Remove the ad keeping the attributes AdView ad = (AdView) myactivity.findViewById(R.id.adView); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ad.getLayoutParams(); LinearLayout parentLayout = (LinearLayout) ad.getParent(); parentLayout.removeView(ad); // Re-initialise the ad ad.destroy(); ad = new AdView(parent); ad.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER); ad.setAdUnitId(myactivity.getString(R.string.banner_ad_unit_id)); ad.setId(R.id.adView); ad.setLayoutParams(lp); parentLayout.addView(ad); // Re-fetch add and check successful load AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(parent.getString(R.string.test_device_id)) .build();