Skip to content

Instantly share code, notes, and snippets.

@yasukotelin
Created August 19, 2020 16:37
Show Gist options
  • Save yasukotelin/1c6c14f5b77bef1a8fd929f741bf2345 to your computer and use it in GitHub Desktop.
Save yasukotelin/1c6c14f5b77bef1a8fd929f741bf2345 to your computer and use it in GitHub Desktop.
CoordinatorLayoutでBottomの要素を消す挙動をするBehavior
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