unity3d – Determining actual height of an Admob SmartBanner in Unity for Android – Stack Overflow

1 min


0

So I’m implementing admob banners into my Unity 4.6 Android recreation. I’ve the banner on the backside and must account for it in my UI. Specifically I must know precisely how tall it’s, however I’m having bother with figuring this out.

Based on the knowledge discovered right here the Smart Banner ought to be 32, 50, or 90 pixels tall, relying on machine height. This does not appear to usually be the case although.

Some looking would appear to point it’s because of density pixels. So I try to convert the acknowledged pixel height utilizing px = dp * (Screen.dpi/ 160). So for instance if I decide the banner height ought to be 90 pixels, I’d use bannerHeight = 90 * (Screen.dpi / 160). This appears to work on some units however not others.

For instance my Nexus Four has a DPI of 320. Using the above it might appear to point that the banner ought to be 180 pixels tall, however the banner seems to truly be about 90 pixels tall. But on the Nexus 7 (which has a dpi of 166), the banner seems to be about 120 pixels tall when the formulation would point out it ought to be ~93.

So I suppose I don’t know how to determine how tall the banner is definitely going to be, and I have not discovered a method to get this data from the API. My code for calling the banner is fairly inventory:

The hyperlink you gave says that the Smart banner could have a height of

The Nexus Four has a DPI of ~320 dp. Given that it is a cellphone, it will have an advert with a height of 50 dp.
Using the formulation, it really works out to 50 * 320 / 160 = 100 pixels (near your actual banner’s height)

The Nexus 7s I regarded up have both a 216 dp (2012) or 323 dp (2013), so I do not fairly know which mannequin has 166 dp.
But let’s assume that it is 216 dp, then being a pill, advert height in dp is 90. Therefore, pixels = 90 * 216 / 160 = 121.5, as soon as once more near your banner’s actual height.

However, I consider that the 400 & 720 MIGHT even be expressed in dp? i.e. 400 pixels in an mdpi machine. Your Nexus Four being an xhdpi machine (320 dp), with a height of 1280 pixels then could be the identical as an mdpi machine of height 640 pixels, falling throughout the vary for an advert height of 50 dp.

Bottomline, your calculations appear legitimate. Stick to the primary set of guidelines, and it is best to see constant outcomes.


What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win

0 Comments

Your email address will not be published. Required fields are marked *

Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Meme
Upload your own images to make custom memes
Video
Youtube, Vimeo or Vine Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format