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.