android admob resize on landscape

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.

Leave a Comment