Skip to content

Instantly share code, notes, and snippets.

@arekolek
Created April 16, 2020 18:11
Show Gist options
  • Save arekolek/ca6c0e9402cc20a5d9c9de5f08dc43ab to your computer and use it in GitHub Desktop.
Save arekolek/ca6c0e9402cc20a5d9c9de5f08dc43ab to your computer and use it in GitHub Desktop.
Convert dp to px
interface HasContext {
fun getContext(): Context
val Int.dp
get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), getContext().resources.displayMetrics).toInt()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment