Last active
November 18, 2020 20:31
-
-
Save Skyyo/8c6ff767cf90a580b6a5232f7e339611 to your computer and use it in GitHub Desktop.
#extensions
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
package com.skyyo.ext | |
import android.content.res.Resources | |
fun Float.dp(): Float = this * density + 0.5f | |
fun Int.dp(): Int = (this * density + 0.5f).toInt() | |
fun Int.sp(): Float = (this * scaledDensity + 0.5f) | |
val density: Float | |
get() = Resources.getSystem().displayMetrics.density | |
val scaledDensity: Float | |
get() = Resources.getSystem().displayMetrics.scaledDensity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment