Personal Blog
written by reiti
a blog by
reiti.net
Project Home
Screenshots
Blog Posts
Forum
<< Opening your own Apple Store
Android Report 07/2012 >>
2012-08-08 16:14
Admob Banner Sizes in Landscape - Best Approach
Google AdMob is a bit of a pain when it comes to finding the best fitting banner to use on all the different screen sizes.

That question get worse, when it comes for use on apps/games in landscape mode - there is nearly approach which will fit the screen well.

So then, having that problem myself I was trying around different things, how I could fill my "ad-area" at the bottom of the screen best.



Warning


WARNING! Placing multiple banners on one site is against the admob publisher ToS! So just see it as an approach of filling the advertising area, this is just an example on how to do it - you may fill the second place with your own banners, whatever - not sure if that would comply to the ToS xD

Let's go



First of all, there is a limited amount of available banner sizes - for our approach the interesting ones are:

IAB_BANNER (468x60) and BANNER (320x50) - those values are specified in DIPS! And that's a bit messy when making a game which does rely on real pixels instead of dips.

The IAB_Leaderboard will fit very rarely on any screen except big tablets, so wi will not use it in this approach, fill free, to do so.

First of all we'll need to figure out the actual dip-width of available space. You can do it like this:


final float density = getResources().getDisplayMetrics().density;
int width = getWindowManager().getDefaultDisplay().getWidth();
width = Math.round(((float)width )/density);


(we are using round to get the best fitting value otherwise you may end up with a missing pixel)

so know, we will construct our banners dependend on the available width of the device. Because no banner will fill this area completely we use a simple approach: Show two(!) banners next to each other if there is too much space available.

So if the dip-width is greater than 936 (=468*2) than we display two IAB_BANNERS. Otherwise if there is enough room for two BANNER, we use that. If that fails also, we use a SMART_BANNER (available since admob sdk 6) - which is not very heigh so fits well on small screens and spans over the full width.

Normally I use a fixed height View for displaying the ads and fill the rest with the game view. So we need to get the desired height of that as-view


if( width >= 936 ) // tablet
{
height = Math.round(density*60f);
}
else if( width >= 640 )
{
height = Math.round(density*50f);
}
else height = Math.round(density*32f);


We now have the desired height in PIXEL for the desired DIP height of the banner (smartbanners on landscape are always 32 dips height)

All you have to do now, is construct your Ad Area for the different approaches.


LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,height);
if( w >= 936 )
{
LinearLayout.LayoutParams pp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
pp.weight = 1.0f;
adview1 = new AdView(this,AdSize.IAB_BANNER,"adcode");
adview1.setGravity(Gravity.CENTER);
adview2 = new AdView(this,AdSize.IAB_BANNER,"adcode");
adview2.setGravity(Gravity.CENTER);
LinearLayout l = new LinearLayout(this);
l.setGravity(Gravity.CENTER);
l.setOrientation(LinearLayout.HORIZONTAL);
l.addView(adview1,pp);
l.addView(adview2,pp);
layout.addView(l,adParams);
}
else if( w >= 640 )
{
LinearLayout.LayoutParams pp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
pp.weight = 1.0f;
adview1 = new AdView(this,AdSize.BANNER,"adcode");
adview1.setGravity(Gravity.CENTER);
adview2 = new AdView(this,AdSize.BANNER,"adcode");
adview2.setGravity(Gravity.CENTER);
LinearLayout l = new LinearLayout(this);
l.setGravity(Gravity.CENTER);
l.setOrientation(LinearLayout.HORIZONTAL);
l.addView(adview1,pp);
l.addView(adview2,pp);
layout.addView(l,adParams);
}
else // phone
{
adview1 = new AdView(this,AdSize.SMART_BANNER,"adcode");
adview2 = null;
layout.addView(adview1,adParams);
}


It's some lines of code, what actually happens is, that in the double-banner case there is a horizontal layout created with two adviews in it.

We do that for the 2xIAB_BANNER and for the 2xBANNER. If none of them fits we use the SMART_BANNER to fill the area.

For sure, you can tweak that even more and break it down to all possible screen sizes out there, there may be screen widths where 1 IAB_BANNER fits completely or where 1 BANNER fits completely. It's up to you to do that additional work.

Also be aware, that you may get equal banners - not always, but it happens, especially for the IAB_BANNERS the ad inventory is a bit lower then for the default BANNER sizes. Also remember, that you will not get image ads on the landscape SMART_BANNER from admob, there is only text available for landscape arrangements. That is really no perfect solution and normally I would recommend to not use SMART_BANNER at all in landscape (because it is weird and does not support heigher ads than 32 dips) but in this case it is a fallback for small screens, where you may like to have more room for the actuall game, which may be the reason for the low height of the smart banner :-)

Let me know, what you think of it, I have just released this approach and are curious how it goes and if users complain about it (don't think so, overall, banners are now smaller than before)
most popular at reiti.net:
Robo Miner
for Android
Personal Blog
of reiti.net

Age of Asteroids on Greenlight!
advertisement:
Leave a Reply
Name: (Required)
Mail: (will not be published) (Required)
Website: (optional)
Anti Spam: 5 + 5 = ?
Reply:
Privacy Policy
© 2024 Peter Reitinger. All Rights Reserved