How to get Screen Size and Orientation in Android

Waqas Anwar
30 July 2011
4591 Views

Sometimes it is important to know the width, height and screen orientation of the device so that you can re-arrange or re-size your views dynamically. Here is the code you can use to get width, height and orientation pragmatically.

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

int width = display.getWidth();
int height = display.getHeight();
int orientation = display.getOrientation();