Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Created May 6, 2019 08:05
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 DawnImpulse/a6dad2c47b62672465f20c5e682de8e0 to your computer and use it in GitHub Desktop.
Save DawnImpulse/a6dad2c47b62672465f20c5e682de8e0 to your computer and use it in GitHub Desktop.
Calculate dynamic height for content on screen
// get height based on screen width
fun getDynamicHeight(context: Context, width: Int, height: Int): Int {
val point = displayDimensions(context)
val h = ((point.x - dpToPx(16, context)) * height) / width
return if (h > (point.y - dpToPx(48, context)))
point.y - dpToPx(48, context)
else
h
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment