仅仅两天后,我才知道SMART_BANNER并不是获得最佳点击率的最佳选择,我们应该在admob的广告尺寸之间动态切换。
这是我编写的Java代码。在4英寸模拟器上运行代码时,我看到请求728x90广告,并且响应无效的广告尺寸。(错误描述是广告无法适合当前屏幕)。帮助:
AdSize adsize = AdSize.SMART_BANNER;
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int orientation = display.getOrientation();
if(width >= 728 && height >= 90 ) {
adsize = AdSize.IAB_LEADERBOARD;
System.out.println("728 x 90");
} else if (width >= 468 && height >= 60 ) {
adsize = AdSize.IAB_BANNER;
System.out.println("468 x 60");
} else if (width >= 320 && height >= 50 ) {
adsize = AdSize.BANNER;
System.out.println("320 x 50");
}
LinearLayout adContainer = (LinearLayout) findViewById(R.id.cakes);
adView = new AdView(this, adsize, "xxxxxxxxxx");
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
// Place the ad view.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
adContainer.addView(adView, params);
getWindowManager().getDefaultDisplay().getWidth()
返回以像素为单位的宽度。您需要根据与密度无关的像素的宽度来决定显示哪个横幅。
我很久以前决定,最好的解决方案是使用Android资源配置来指定adBannerSize。例如
final AdSize adSize;
final int adBannerSize = getResources().getInteger(R.integer.adBannerSize);
switch (adBannerSize) {
case 1 :
adSize = AdSize.BANNER;
break;
case 2 :
adSize = AdSize.IAB_BANNER;
break;
case 3 :
adSize = AdSize.IAB_LEADERBOARD;
break;
default:
Log.w(TAG, "No AdSize specified");
adSize = AdSize.BANNER;
break;
}
然后,您可以轻松配置广告横幅的大小,以与您打算支持的任何设备配置相匹配。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句