Created
January 7, 2018 21:43
-
-
Save zeeshanaslam78/0e49fcdd9a966e014ec622dec03fb265 to your computer and use it in GitHub Desktop.
Convert dp to px an px to dp in Android
This file contains hidden or 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 int dpToPx(int dp) | |
{ | |
return (int) (dp * Resources.getSystem().getDisplayMetrics().density); | |
} | |
public static int pxToDp(int px) | |
{ | |
return (int) (px / Resources.getSystem().getDisplayMetrics().density); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment