I am using Admob for ads in my app and I ran into a problem. Whenever I turn the screen to landscape mode, the ad shows up but it's the same size as it was in portrait mode. This problem occured after I added this xml declaration in my manifest to my main activity that was necessary to keep the main parts of the app functioning smoothly:
android:configChanges="orientation|keyboardHidden|screenSize"
I am using smart banner in my ad for the size:
ads:adSize="SMART_BANNER"
I have attached pictures of this problem:


What do I have to do to get the ad to resize properly in landscape mode without deleting
android:configChanges="orientation|keyboardHidden|screenSize"  
in the manifest for my main activity?
this is how I solved it:
@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());
    }
regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With