Skip to content

Instantly share code, notes, and snippets.

@JonathandelaSen
Last active March 11, 2017 11:43
Show Gist options
  • Save JonathandelaSen/4e205a2120712267322ea6f6467467cd to your computer and use it in GitHub Desktop.
Save JonathandelaSen/4e205a2120712267322ea6f6467467cd to your computer and use it in GitHub Desktop.
Android Get screen size
public static float getScreenWidthDps(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return displayMetrics.widthPixels / displayMetrics.density;
}
public static float getScreenWidthPxs(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
}
public static float getScreenHeightDps(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return displayMetrics.heightPixels / displayMetrics.density;
}
public static float getScreenHeightPxs(Context context) {
return context.getResources().getDisplayMetrics().heightPixels;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment