I faced the same problem, but found a work-around.
My AdView sits at the bottom of the page, inside of a Relative layout. It looks correct when loaded, so I assumed the LayoutParams
were correct. To fix this issue, I had to remove everything from the RelativeLayout
, create a new AdView, and add it all back in the correct order, with the original LayoutParams
.
Something like:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
AdView adView = (AdView)findViewById(R.id.adView);
View contentFrame = findViewById(R.id.contentFrameLayout);
RelativeLayout parent = (RelativeLayout) adView.getParent();
LayoutParams mapFrameParams = contentFrame.getLayoutParams();
LayoutParams adViewParams = adView.getLayoutParams();
parent.removeView(adView);
parent.removeView(contentFrame);
AdView newAdView = new AdView(this, AdSize.SMART_BANNER, getString(R.string.admob_pubId));
newAdView.setId(R.id.adView);
parent.addView(newAdView, adViewParams);
parent.addView(contentFrame,mapFrameParams);
newAdView.loadAd(new AdRequest());
}
This works for me, but still feels like a hack.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…