Created
March 19, 2019 09:28
-
-
Save eoinahern/2a693a761cf1d6dffa85d7d92a450f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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