AdSize类有getWidthInPixels()和getHeightInPixels()方法来获取广告的大小。虽然,他们正确地工作在横幅,但他们不工作的SMART_BANNER。他们总是会回来-2。
您能建议我一种在运行时获取AdView大小的方法吗?
发布于 2013-01-07 22:11:23
如果使用的是Google服务库,只需使用:
int widthPixels = AdSize.SMART_BANNER.getWidthInPixels(this);
int heightPixels = AdSize.SMART_BANNER.getHeightInPixels(this);在旧的独立安卓AdMob SDK中,您必须以黑客的方式完成它:
免责声明:这是创建AdSize的错误方法。不将此AdSize传递给AdView构造函数!
希望智能横幅实现将在未来的版本中得到修正,这样您就不必做这个麻烦的解决办法了。但这是如何做到的:
// 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
复制相似问题