Last active
March 11, 2017 11:43
-
-
Save JonathandelaSen/4e205a2120712267322ea6f6467467cd to your computer and use it in GitHub Desktop.
Android Get screen size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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