簡體   English   中英

Admob SMART_BANNER大小

[英]Admob SMART_BANNER size

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中,您必須采用駭人聽聞的方式:

免責聲明:這是創建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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM