Admob SMART_BANNER size

前端 未结 1 371
渐次进展
渐次进展 2020-12-10 17:30

The AdSize class has getWidthInPixels() and getHeightInPixels() methods to obtain size of the ad. Although, they work correctly for BANNER, they don\'t work SMART_BANNER. Th

1条回答
  •  有刺的猬
    2020-12-10 17:56

    If you're using the Google Play services library, you can simply use:

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

    In the old standalone Android AdMob SDK, you have to do it the hacky way:

    Disclaimer: This is the incorrect way to create an AdSize. Do NOT pass this AdSize into the AdView constructor!

    Hopefully the smart banner implementation will be fixed in future versions so you don't have to do this hacky workaround. But here is how it can be done:

    // 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.
    

    0 讨论(0)
提交回复
热议问题