Created
August 19, 2020 16:37
-
-
Save yasukotelin/1c6c14f5b77bef1a8fd929f741bf2345 to your computer and use it in GitHub Desktop.
CoordinatorLayoutでBottomの要素を消す挙動をするBehavior
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 BottomWidgetBehavior<V : View>(context: Context, attrs: AttributeSet) : | |
CoordinatorLayout.Behavior<V>(context, attrs) { | |
override fun onStartNestedScroll( | |
coordinatorLayout: CoordinatorLayout, | |
child: V, | |
directTargetChild: View, | |
target: View, | |
axes: Int, | |
type: Int | |
): Boolean { | |
Timber.d("axes ---> $axes") | |
return axes == ViewCompat.SCROLL_AXIS_VERTICAL | |
} | |
override fun onNestedPreScroll( | |
coordinatorLayout: CoordinatorLayout, | |
child: V, | |
target: View, | |
dx: Int, | |
dy: Int, | |
consumed: IntArray, | |
type: Int | |
) { | |
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type) | |
child.translationY = | |
kotlin.math.max( | |
0f, | |
kotlin.math.min( | |
child.height.toFloat() + child.marginBottom, | |
child.translationY + dy | |
) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment