Last active
September 8, 2018 20:18
-
-
Save BenjaminEarley/2aa30e41797af2ba77f3b8e8cad38255 to your computer and use it in GitHub Desktop.
Android: Extensions for converting dp values to px values
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 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