AdSize类具有getWidthInPixels()和getHeightInPixels()方法以获取广告的大小.虽然它们适用于BANNER,但它们不适用于SMART_BANNER.他们总是回归-2.
您能否建议我在运行时获取AdView大小的方法?
Eri*_*lag 18
如果您使用的是Google Play服务库,则只需使用:
int widthPixels = AdSize.SMART_BANNER.getWidthInPixels(this);
int heightPixels = AdSize.SMART_BANNER.getHeightInPixels(this);
Run Code Online (Sandbox Code Playgroud)
在旧的独立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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8626 次 |
| 最近记录: |