Admob SMART_BANNER尺寸

时间:2013-01-04 18:32:31

标签: android admob

AdSize类使用getWidthInPixels()和getHeightInPixels()方法来获取广告的大小。虽然它们适用于BANNER,但它们不适用于SMART_BANNER。他们总是返回-2。

您能否建议我在运行时获取AdView大小的方法?

1 个答案:

答案 0 :(得分:17)

如果您使用的是Google Play服务库,则可以使用:

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

在旧的独立Android AdMob SDK中,您必须采用hacky方式:

免责声明:这是创建AdSize的错误方法。 请勿将此AdSize传递给AdView构造函数!

希望智能横幅实现将在未来版本中修复,因此您无需执行此hacky解决方法。但这是如何做到的:

// 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.
相关问题