0

I'm trying to get width and height from a map fragment. However methods getWidth and getHeight are deprecated and i dont now how to do in google v2.

I used to do like this way:

display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();

Please someone help

1 Answers1

1

If I understand, you're trying to get screen dimensions, maybe you should look at this post:

if you want the the display dimensions in pixels you can use getSize:

Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size); 
int width = size.x; 
int height = size.y;

See this post for details How to get screen dimensions as pixels in Android.

halfer
  • 19,824
  • 17
  • 99
  • 186
Quentin Klein
  • 1,263
  • 10
  • 27
  • what if you have other views on the screen and you want the dimensions of the mapview only? – Paul Alexander Aug 14 '15 at 11:04
  • 1
    You should be able to do that with a `ViewTreeObserver` like explained in this post http://stackoverflow.com/questions/3779173/determining-the-size-of-an-android-view-at-runtime. The goal is to compute the size at runtime and observe the view you want to get its size. – Quentin Klein Aug 14 '15 at 11:56