Is it possible to easily center the content of the view below AppBarLayout, inside CoordinatorLayout?
try custom behaviour .
class ViewBelowAppBarBehavior @JvmOverloads constructor(
context: Context? = null, attrs: AttributeSet? = null) : CoordinatorLayout.Behavior<View>(context, attrs) {
override fun layoutDependsOn(parent: CoordinatorLayout?, child: View?, dependency: View?) = dependency is AppBarLayout
override fun onDependentViewChanged(parent: CoordinatorLayout?, child: View?, dependency: View?): Boolean {
val appBar = dependency as AppBarLayout
// т.к. y - отрицательное число
val currentAppBarHeight = appBar.height + appBar.y
val parentHeight = parent?.height ?: 0
val placeHolderHeight = (parentHeight - currentAppBarHeight).toInt()
child?.layoutParams?.height = placeHolderHeight
child?.requestLayout()
return false
}
}