-
-
Save carlosgub/6a13a499d878ca9af34ccb5451c93768 to your computer and use it in GitHub Desktop.
Px to Dp
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
/** | |
* This method converts device specific pixels to density independent pixels. | |
* | |
* @param px A value in px (pixels) unit. Which we need to convert into db | |
* @param context Context to get resources and device specific display metrics | |
* @return A float value to represent dp equivalent to px value | |
*/ | |
public float convertPxToDp(Context context, float px) { | |
return px / context.getResources().getDisplayMetrics().density; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment