Skip to content

Instantly share code, notes, and snippets.

@gpeal
Last active November 2, 2021 18:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpeal/c33ed4c61697a9262c5914ccd7e10df0 to your computer and use it in GitHub Desktop.
Save gpeal/c33ed4c61697a9262c5914ccd7e10df0 to your computer and use it in GitHub Desktop.
/**
* Call this function on a dp value and it will return the equivalent
* number of pixels for the current display.
* e.g. 8.dp
*/
val Number.dp get() = toFloat() * (Resources.getSystem().displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment