Skip to content

Instantly share code, notes, and snippets.

@hleinone
Created February 4, 2019 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hleinone/ffa1e8793efb396333cee256a85b8480 to your computer and use it in GitHub Desktop.
Save hleinone/ffa1e8793efb396333cee256a85b8480 to your computer and use it in GitHub Desktop.
Density pixel calculation helper
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