Created
July 8, 2020 11:58
-
-
Save hirauchg/d5bac4eeab4aeeb3cc018b1d49eb832b to your computer and use it in GitHub Desktop.
px ↔ dpの変換方法 - 1
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
fun dpTopx(dp: Int, context: Context): Float { | |
val metrics = context.getResources().getDisplayMetrics() | |
return dp * metrics.density | |
} | |
fun pxToDp(px: Int, context: Context): Float { | |
val metrics = context.getResources().getDisplayMetrics() | |
return px / metrics.density | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment