Share the post "How To Auto Adjust Google AdMob Container On Orientation Change In Android"
There is no method to automatically change your Android app’s container size for showing Google AdMob ads. While it does re-adjust itself whenever the orientation changes, it does not resize itself to the correct size.
Try changing your device’s orientation from portrait to landscape mode and you will see that the height is the same. The result is that the height of the ad container shown is too big just like when its orientation is in portrait mode.
The workaround to make the ad container resize correctly according to orientation change like the image below is to remove the ad container in your layout view and add it back.
Say this is your code for adding the ad container view to your layout view.
|
1 2 3 4 5 6 7 8 |
private void configureAds() { FrameLayout fl = (FrameLayout) findViewById(R.id.adContainer); fl.removeAllViews(); AdSize adsize = com.google.ads.AdSize.SMART_BANNER; adView = new AdView(this, adsize, Default.ID_ADMOB); fl.addView(adView); adView.loadAd(new AdRequest()); } |
Then place the method in the onConfigurationChanged().
|
1 2 3 4 5 |
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); configureAds(); } |