Admob Smart Banners - Adjusting for different dpi / screen sizes

1,315 views
Skip to first unread message

benw...@gmail.com

unread,
Jun 28, 2018, 11:37:12 PM6/28/18
to Google Mobile Ads SDK Developers
Hi,

I'm trying to work out how much of the screen (in pixels) my Admob smart banner will take up in height on various devices.  I have a smart banner at the top of my game.  While Smart Banners automatically take care of the width, I need to know the height.  From the Admob page I see this:

Ad heightScreen height
32 dp≤ 400 dp
50 dp> 400 dp and ≤ 720 dp
90 dp> 720 dp

I need to know exactly how tall in screen pixels the ad will be so I can calculate exactly how much of the rest of the screen can be used as playable space for my game.

I've seen some articles showing the formula to calculate screen pixels is:  px = dp * (dpi / 160)

I have an iPhone 8 which I'm testing on.  It has a 750x1334 resolution and 326 dpi.

According to this information, I'm calculating the pixel height of a smart banner on my iPhone 8 should be 65.2.   Formula:  32 * (326 / 160) = 65.2 px.

However, the ad on device looks like it's taking up around 100 pixels in height.

What am I doing wrong, and what's the correct formula to calculate this?

Many thanks,

Ben

mobileadssdk-a...@google.com

unread,
Jun 29, 2018, 3:03:50 AM6/29/18
to benw...@gmail.com, Google Mobile Ads SDK Developers
Hi Ben,

Thanks for reaching out to us.

It seems you are referring to the Smart Banner guide for Android, please refer to this guide instead. Also, the formula you have mentioned might not be applicable because iOS uses Points as the unit of measurement. On a standard-resolution screen, one point is equal to one pixel. However, this is not the case in high-resolution screens like iPhone 8 which has doubled scale factor (based on these guidelines).

To answer your question on how to get the height of the Smart Banner in pixels, please refer to the steps below:
  1. Get the Scale Factor of the device by using UIScreen.main.scale method
  2. Get the height of the Banner (ex: bannerView.frame.size.height - this will return the height of the Banner in Points).
  3. Multiply the height of the Banner (in Points) to the Scale Factor (Height x Scale Factor). The result is the height of the Banner in pixels.
Additionally, I modified this BannerExample app to show the steps above in actual Xcode project and when I ran the project in iPhone 8 simulator, I got 100 pixels as the height of the Banner.

Regards,
Steven Balan
Mobile Ads SDK Team

Roman Vasilyev

unread,
Jun 29, 2018, 3:14:12 AM6/29/18
to mobileadssdk-a...@google.com, benw...@gmail.com, google-adm...@googlegroups.com
Is it possible to make Native ads available for my account?

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/186t5h8000000000o04i0e001uoff0y68mjac1m70o30c1g68p3cc9h%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Regards

mobileadssdk-a...@google.com

unread,
Jun 29, 2018, 4:22:28 AM6/29/18
to Roman Vasilyev, benw...@gmail.com, google-adm...@googlegroups.com
Hi Roman,

Please refer to my response in this thread.

benw...@gmail.com

unread,
Jun 30, 2018, 12:25:35 PM6/30/18
to google-adm...@googlegroups.com
Thanks for the instructions.  I'm actually using Unity (C#) for development.  I have the AdMob SDK integrated though.  How do I access UIScreen.main.scale and bannerView.frame.size.height from the AdMob SDK?  I wasn't able to find references to these.  I tried AdSize.SmartBanner.Height which is available via the AdMob SDK, but it just returns zero on device.

Many thanks!

mobileadssdk-a...@google.com

unread,
Jul 2, 2018, 3:44:27 AM7/2/18
to benw...@gmail.com, Google Mobile Ads SDK Developers
Hi there,

Since you have mentioned that you are using Unity, you may try to use the GetHeightInPixels() method of the BannerView object.

benw...@gmail.com

unread,
Jul 2, 2018, 12:33:24 PM7/2/18
to Google Mobile Ads SDK Developers
Thanks.  I've got the latest Admob package installed, but I don't see that option.  I'm using GoogleMobileAds.Api.  When I type BannerView I only get the autofill option of "Equals" or "ReferenceEquals".  How do I access the GetHeightInPixels() function?  Many thanks

mobileadssdk-a...@google.com

unread,
Jul 2, 2018, 11:17:39 PM7/2/18
to benw...@gmail.com, Google Mobile Ads SDK Developers
Hi,

Please download the modified HelloWorld sample app from this link and refer to line 199 of the GoogleMobileAdsDemoScript.cs file to see the sample use of GetHeightInPixels() method.
Reply all
Reply to author
Forward
0 new messages