Skip to content

Instantly share code, notes, and snippets.

@BenjaminEarley
Last active September 8, 2018 20:18
Show Gist options
  • Save BenjaminEarley/2aa30e41797af2ba77f3b8e8cad38255 to your computer and use it in GitHub Desktop.
Save BenjaminEarley/2aa30e41797af2ba77f3b8e8cad38255 to your computer and use it in GitHub Desktop.
Android: Extensions for converting dp values to px values
fun Float.dipsToPixels() =
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this,
Resources.getSystem().displayMetrics
)
fun Int.dipsToPixels() = toFloat().dipsToPixels().toInt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment