Created
September 5, 2017 02:06
-
-
Save maxost/aefa9236dedce8ccb65b8e8d2f7cd518 to your computer and use it in GitHub Desktop.
Kotlin: dp-px converters
This file contains hidden or 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 Int.dp2px(context: Context): Int = (this * context.resources.displayMetrics.density).toInt() | |
fun Int.px2dp(context: Context): Int = (this / context.resources.displayMetrics.density).toInt() | |
fun Float.dp2px(context: Context): Float = this * context.resources.displayMetrics.density | |
fun Float.px2dp(context: Context): Float = this / context.resources.displayMetrics.density |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment