Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.res.Resources
- /** Value in dp */
- val Int.dp: Int
- get() = (this / Resources.getSystem().displayMetrics.density).toInt()
- /** Value in px */
- val Int.px: Int
- get() = (this * Resources.getSystem().displayMetrics.density).toInt()
- /** Value in dp */
- val Float.dp: Float
- get() = (this / Resources.getSystem().displayMetrics.density)
- /** Value in px */
- val Float.px: Float
- get() = (this * Resources.getSystem().displayMetrics.density)
- // with these extensions, we can do:
- // val width = 4.dp
- // val height = 2.5f.dp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement