Wednesday, October 20, 2010

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();

No comments:

Post a Comment