Created
June 21, 2019 22:14
-
-
Save carlosgub/f809ae550bfdf5f90cb65196f95d779c to your computer and use it in GitHub Desktop.
Dp to Int
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 dp unit to equivalent pixels, depending on device density. | |
* | |
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels | |
* @param context Context to get resources and device specific display metrics | |
* @return A float value to represent px equivalent to dp depending on device density | |
*/ | |
public float convertDpToPx(Context context, float dp) { | |
return dp * context.getResources().getDisplayMetrics().density; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment