Created
August 3, 2022 18:49
-
-
Save indrih17/d173645d5761be4208373953f68fdf30 to your computer and use it in GitHub Desktop.
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
/** Перевод из Px в Dp. */ | |
fun Int.pxToDp(displayMetrics: DisplayMetrics = Resources.getSystem().displayMetrics): Int = | |
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, toFloat(), displayMetrics).roundToInt() | |
/** Перевод из Dp в Px. */ | |
fun Int.dpToPx(displayMetrics: DisplayMetrics = Resources.getSystem().displayMetrics): Int = | |
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, toFloat(), displayMetrics).roundToInt() | |
/** Перевод из Sp в Px. */ | |
fun Int.spToPx(displayMetrics: DisplayMetrics = Resources.getSystem().displayMetrics): Int = | |
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, toFloat(), displayMetrics).roundToInt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment