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

廉价感情. 提交于 2019-12-06 13:15:22

问题


I'm trying to integrate ads into my Android app using AdWhirl and AdMob.

The AdWhirl site gave me the following code to use:

AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.layoutAdWhirl);

int diWidth = 320;
int diHeight = 52;
int density = (int) getResources().getDisplayMetrics().density;

int scaledWidth = (int) (diWidth * density);
int scaledHeight = (int) (diHeight * density);

adWhirlLayout.setAdWhirlInterface(this);
adWhirlLayout.setMaxWidth(scaledWidth);
adWhirlLayout.setMaxHeight(scaledHeight);

This works just fine on some of my emulators, but when I try some smaller or older emulators, I get the following error in LogCat:

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

What am I supposed to do if I'm using their code for requesting an appropriately sized ad, but then they won't display that ad?


回答1:


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.



来源:https://stackoverflow.com/questions/9639771/admob-via-adwhirl-not-enough-space-to-show-ad-wants-480-75-has-320-52

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