Last active
August 29, 2015 14:18
-
-
Save vinaysshenoy/fa8eb8b2447f5e7451af to your computer and use it in GitHub Desktop.
DP/PX Conversion
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
/** | |
* Converts a raw pixel value to a dp value, based on the device density | |
*/ | |
private static float pxToDp(float px) { | |
return px / Resources.getSystem().getDisplayMetrics().density; | |
} | |
/** | |
* Converts a raw dp value to a pixel value, based on the device density | |
*/ | |
public static float dpToPx(float dp) { | |
return dp * Resources.getSystem().getDisplayMetrics().density; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment