Created
February 4, 2019 14:12
-
-
Save hleinone/ffa1e8793efb396333cee256a85b8480 to your computer and use it in GitHub Desktop.
Density pixel calculation helper
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
import android.content.res.Resources | |
import android.util.TypedValue | |
object OneDp { | |
fun init(resources: Resources) { | |
oneDp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, resources.displayMetrics) | |
} | |
} | |
private var oneDp = 0f | |
val Int.dp: Float | |
get() = this * oneDp | |
val Float.dp: Float | |
get() = this * oneDp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment