Skip to content

Instantly share code, notes, and snippets.

@z0lope0z
Last active July 21, 2022 11:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save z0lope0z/59ed096ba8d202812052 to your computer and use it in GitHub Desktop.
Save z0lope0z/59ed096ba8d202812052 to your computer and use it in GitHub Desktop.
Get screen width and height programmatically in Android
// orig: http://stackoverflow.com/questions/6465680/how-to-determine-the-screen-width-in-terms-of-dp-or-dip-at-runtime-in-android
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment