Skip to content

Instantly share code, notes, and snippets.

@vinaysshenoy
Last active August 29, 2015 14:18
Show Gist options
  • Save vinaysshenoy/fa8eb8b2447f5e7451af to your computer and use it in GitHub Desktop.
Save vinaysshenoy/fa8eb8b2447f5e7451af to your computer and use it in GitHub Desktop.
DP/PX Conversion
/**
* 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