Skip to content

Instantly share code, notes, and snippets.

@asiletto
Created July 23, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asiletto/26f97784a4012ec8d605 to your computer and use it in GitHub Desktop.
Save asiletto/26f97784a4012ec8d605 to your computer and use it in GitHub Desktop.
Get width height and orientation in android
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
float density = getResources().getDisplayMetrics().density;
float dpHeight = outMetrics.heightPixels / density;
float dpWidth = outMetrics.widthPixels / density;
Log.d("SIZE","height: "+dpHeight+"dp, width:"+dpWidth+"dp, orientation:"+display.getRotation());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment