8

In my Android app, I have an AdView:

AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);

How do I get the size of this in pixels?

Sufian
  • 6,405
  • 16
  • 66
  • 120
BenH
  • 2,100
  • 2
  • 22
  • 33

3 Answers3

16

As mentioned in the answer by Flynn, an adView is 320 dp by 50 dp. To convert 50 dp to pixels, do

(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());

(and similarly for 320 dp).

BenH
  • 2,100
  • 2
  • 22
  • 33
  • Alse you can convert in this way DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); final int addHeight = (int) Math.ceil(50 * metrics.density); – Gelldur Nov 06 '13 at 10:32
13

You can use following methods from the AdSize class to get its size in pixels:

  1. getWidthInPixels(Context context),
  2. getHeightInPixels(Context content).
ThomasW
  • 16,981
  • 4
  • 79
  • 106
7

An adView is 320x50, and if the view does not fit, then it is not displayed.

http://code.google.com/mobile/ads/docs/android/intermediate.html

Flynn
  • 5,903
  • 7
  • 38
  • 55