Skip to content

Instantly share code, notes, and snippets.

@eoinahern
Created March 19, 2019 09:28
Show Gist options
  • Save eoinahern/2a693a761cf1d6dffa85d7d92a450f98 to your computer and use it in GitHub Desktop.
Save eoinahern/2a693a761cf1d6dffa85d7d92a450f98 to your computer and use it in GitHub Desktop.
class CustomShrinkLayoutBehavior(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<NestedScrollView>(context, attrs) {
private var screenHeight: Int = context.resources.displayMetrics.heightPixels
override fun layoutDependsOn(parent: CoordinatorLayout, child: NestedScrollView, dependency: View): Boolean {
return dependency is AppBarLayout
}
override fun onDependentViewChanged(parent: CoordinatorLayout, child: NestedScrollView, dependency: View): Boolean {
if (dependency is AppBarLayout) {
updateAssetChartSize(child, dependency)
}
return true
}
private fun updateAssetChartSize(child: View, dependency: View) {
val chart = (child as NestedScrollView)
val layoutParams = child.layoutParams
layoutParams.height = screenHeight - dependency.bottom
chart.layoutParams = layoutParams
chart.translationY = dependency.bottom.toFloat()
chart.invalidate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment