Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active November 18, 2020 20:31
Show Gist options
  • Save Skyyo/8c6ff767cf90a580b6a5232f7e339611 to your computer and use it in GitHub Desktop.
Save Skyyo/8c6ff767cf90a580b6a5232f7e339611 to your computer and use it in GitHub Desktop.
#extensions
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