2

How to get screen size (in pixels)? I used

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

but it doesn't work...

petey
  • 16,914
  • 6
  • 65
  • 97

2 Answers2

0

use this

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth(); 
int height = display.getHeight();
stinepike
  • 54,068
  • 14
  • 92
  • 112
  • I'm curious, does ``display.getWidth()`` & ``getHeight()`` return different values than ``display.getSize(Point)`` as OP had tried? – harism Apr 23 '13 at 18:04
  • actually getsize is not available in lower api version ..@harism.. but I think this is not the case here .. :? – stinepike Apr 23 '13 at 18:08
  • I see, should have read the documentation more closely. – harism Apr 23 '13 at 18:11
0
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();     
int width = display.getWidth();
int height = display.getHeight();
Phil
  • 35,852
  • 23
  • 123
  • 164