Admob ad not resizing correctly upon screen orientation [Includes Pictures]

admob, android, java

Solution

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

Problem

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?

Original source

Related problems