gpt4 book ai didi

android - Admob SMART_BANNER 尺寸

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:32 26 4
gpt4 key购买 nike

AdSize 类具有获取广告尺寸的 getWidthInPixels() 和 getHeightInPixels() 方法。尽管它们对 BANNER 有效,但对 SMART_BANNER 无效。他们总是返回 -2。

能否请您建议我一种在运行时获取 AdView 尺寸的方法?

最佳答案

如果您使用的是 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.

关于android - Admob SMART_BANNER 尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14162819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com