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?
Couple of things here:
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.
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