Android 更改屏幕方向时,Admob横幅消失
我已经成功地在我的android应用程序中集成了admob横幅,并且在我的项目清单文件中使用了以下配置Android 更改屏幕方向时,Admob横幅消失,android,admob,screen-orientation,adsense,Android,Admob,Screen Orientation,Adsense,我已经成功地在我的android应用程序中集成了admob横幅,并且在我的项目清单文件中使用了以下配置 <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 但是
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
但是,当我更改设备的屏幕方向时,adview会消失吗
我做错了什么?我使用
onConfigurationChanged
方法解决了这个问题,问题是当我返回到纵向模式时,广告单元大小大于可用大小
这是解决办法
@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);
}
上面的示例将横幅设置为其原始大小。高度和宽度变量不在任何地方使用。还对height adView.setAdsize的线路开关值感到困惑。。。等等,这是评论吗???