Tuesday, October 11, 2011

Get Android device screen width

Quick tip on how to get the width of your device in code. Don't use View.getWidth() -- gives the wrong result.



Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
int screenWidth = display.getWidth();