Skip to content

Instantly share code, notes, and snippets.

@hirauchg
Created July 8, 2020 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirauchg/d5bac4eeab4aeeb3cc018b1d49eb832b to your computer and use it in GitHub Desktop.
Save hirauchg/d5bac4eeab4aeeb3cc018b1d49eb832b to your computer and use it in GitHub Desktop.
px ↔ dpの変換方法 - 1
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