Admob的横幅大小不同的设备 [英] Admob banner size for different devices
问题描述
就在两天后,我才知道,SMART_BANNER是不是最好好的点击率,我们应该广告尺寸之间的AdMob的动态切换。
下面是Java code,我已经写了。当我跑了code在4英寸模拟器,我看到的728x90的广告请求和响应是无效的广告尺寸。 (错误的描述是,广告不适合当前屏幕)请。帮助:
AdSize adsize = AdSize.SMART_BANNER;
显示显示= getWindowManager()getDefaultDisplay()。
INT宽度= display.getWidth();
INT高= display.getHeight();
INT方向= display.getOrientation();
如果(宽> = 728&安培;&功放;高> = 90){
adsize = AdSize.IAB_LEADERBOARD;
的System.out.println(728×90);
}否则如果(宽> = 468&安培;&功放;高> = 60){
adsize = AdSize.IAB_BANNER;
的System.out.println(468×60);
}否则如果(宽> = 320安培;&功放;高> = 50){
adsize = AdSize.BANNER;
的System.out.println(320×50);
}
的LinearLayout adContainer =(的LinearLayout)findViewById(R.id.cakes);
AD浏览报=新的AD浏览报(这一点,adsize,XXXXXXXXXX);
AdRequest adRequest =新AdRequest();
adView.loadAd(adRequest);
//放置的广告来看。
LinearLayout.LayoutParams PARAMS =新LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
adContainer.addView(AD浏览报,则params);
getWindowManager()。getDefaultDisplay()的getWidth()
返回像素宽度。你必须做一个上旗帜,以展示基于密度独立像素的宽度决定。
我决定在很久以前,最好的解决办法是使用Android资源配置到指定adBannerSize。例如:
最后AdSize adSize;
最终诠释adBannerSize = getResources()getInteger(R.integer.adBannerSize)。
开关(adBannerSize){
情况1 :
adSize = AdSize.BANNER;
打破;
案例2:
adSize = AdSize.IAB_BANNER;
打破;
案例3:
adSize = AdSize.IAB_LEADERBOARD;
打破;
默认:
Log.w(TAG,没有AdSize规定);
adSize = AdSize.BANNER;
打破;
}
然后就可以轻松地配置广告横幅大小,以匹配任何设备的配置,你打算支持。
Just two days back, I came to know that SMART_BANNER is not the best for good CTR and we should dynamically switch between ad sizes for admob.
Here is the Java code, I have written. When I ran the code on a 4inch emulator, I see that 728x90 ad is requested and the response is invalid ad size. (description of error is that ad won't fit the current screen) pls. help:
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()
returns the width in pixels. You need to be making a decision on which banner to show based upon the width in density independent pixels.
I decided a long time ago that the best solution was to use Android resource config to specify the adBannerSize. Eg
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;
}
Then you can easily configure the ad banner size to match whatever device configuration you intend to support.
这篇关于Admob的横幅大小不同的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!