Skip to content

Instantly share code, notes, and snippets.

@karayok
Created January 17, 2018 10:47
Show Gist options
  • Save karayok/63c537a5cb93a967caca718a65b01cad to your computer and use it in GitHub Desktop.
Save karayok/63c537a5cb93a967caca718a65b01cad to your computer and use it in GitHub Desktop.
Get screen size (Android/Kotlin)
// import android.content.Context.WINDOW_SERVICE
// import android.view.WindowManager
// import android.graphics.Point
// privat val size by lazy {
private val size = {
Point().also {
(context.getSystemService(WINDOW_SERVICE) as WindowManager)
.defaultDisplay
.apply { getSize(it) }
}
}
val width = size.x
val height = size.y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment