Skip to content

Instantly share code, notes, and snippets.

@colinrtwhite
Last active September 23, 2018 04:17
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 colinrtwhite/3b2f71313f77266a4507d40cb54a4db5 to your computer and use it in GitHub Desktop.
Save colinrtwhite/3b2f71313f77266a4507d40cb54a4db5 to your computer and use it in GitHub Desktop.
@JvmOverloads @Dimension(unit = Dimension.PX) fun Number.dpToPx(
metrics: DisplayMetrics = Resources.getSystem().displayMetrics
): Float {
return toFloat() * metrics.density
}
@JvmOverloads @Dimension(unit = Dimension.DP) fun Number.pxToDp(
metrics: DisplayMetrics = Resources.getSystem().displayMetrics
): Float {
return toFloat() / metrics.density
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment