I solved it using the onConfigurationChanged
method, Problem was when i do go back to portrait mode the ad-unit size was bigger than the available size.
Here is the solution
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LinearLayout parent= (LinearLayout) adView.getParent();
parent.removeView(adView);
/**
* Admob paremetrization
*/
final float density = getResources().getDisplayMetrics().density;
int width = getWindowManager().getDefaultDisplay().getWidth();
width = Math.round(((float)width )/density);
int height;
if( width >= 936 ) // tablet
{
height = Math.round(density*60f);
}
else if( width >= 640 )
{
height = Math.round(density*50f);
}
else height = Math.round(density*32f);
adView = new AdView(this);
switch value of height adView.setAdSize(AdSize.FULL_BANNER or BANNER SMART_BANNER....);
adView.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxx");
parent.addView(adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("myDeviceId") phone
.build();
adView.loadAd(adRequest);
}