AdMob via AdWhirl: Not enough space to show ad! Wants: 480, 75, Has: 320, 52

对着背影说爱祢 提交于 2019-12-04 20:26:07

Couple of things here:

  1. The AdMob ad needs 320x50 density-independent pixels to show an ad. Every Android device, even the old small ones, meet these specs. The small 240x400 pixel phones are low density, meaning 1px = 0.75dp, and so there are still 320dp in portrait mode to show an ad. Your small emulators are probably in such a state where they are really small (low pixel count), but have medium or high density such that the emulator isn't 320dp wide. Check your emulator settings - they are likely not representative of any device.

  2. The above code to calculate max width and max height isn't necessary. As long as the xml gives the AdWhirlView 320x52dp size (or more preferred, wrap_content), you don't need to grab the device density to calculate these values manually.

UPDATE:

I have a new theory. The error you're displaying where the AdMob SDK Wants: 480, 75 means you're running on a high-density device, because it multiplied 320x50dip by 1.5. However, the piece of code:

int density = (int) getResources().getDisplayMetrics().density;

is casting 1.5 to 1, so the max width and height of the adWhirlLayout were incorrectly set to 320x52 pixels. This would probably have been an issue for low density devices as well, because 0.75 density would have been casted to 0. It may have worked on medium density devices.

The AdWhirl documentation is a bit outdated, but it probably should have said float density instead of int density.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!