仅仅两天前,我就知道SMART_BANNER不是最佳的点击率,我们应该在adob的广告尺寸之间动态切换.
这是我编写的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);
William.. 6
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; }
然后,您可以轻松配置广告横幅大小,以匹配您打算支持的任何设备配置.