Admob SMART_BANNER size

我只是一个虾纸丫 提交于 2019-12-17 19:45:25

问题


The AdSize class has getWidthInPixels() and getHeightInPixels() methods to obtain size of the ad. Although, they work correctly for BANNER, they don't work SMART_BANNER. They always return -2.

Can you please suggest me a way to fetch AdView size during run-time?


回答1:


If you're using the Google Play services library, you can simply use:

int widthPixels = AdSize.SMART_BANNER.getWidthInPixels(this);
int heightPixels = AdSize.SMART_BANNER.getHeightInPixels(this);

In the old standalone Android AdMob SDK, you have to do it the hacky way:

Disclaimer: This is the incorrect way to create an AdSize. Do NOT pass this AdSize into the AdView constructor!

Hopefully the smart banner implementation will be fixed in future versions so you don't have to do this hacky workaround. But here is how it can be done:

// This testSize should not be passed to the AdView constructor.
// Always pass AdSize.SMART_BANNER instead.
AdSize testSize = AdSize.createAdSize(AdSize.SMART_BANNER, this);
int widthPixels = testSize.getWidthInPixels(this);
int heightPixels = testSize.getHeightInPixels(this);
// testSize should not be referenced past this point.


来源:https://stackoverflow.com/questions/14162819/admob-smart-banner-size

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