1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| class NestedParentView : ViewGroup, NestedScrollingParent { override fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean { return true } override fun onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray) { } override fun onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) { } override fun onStopNestedScroll(target: View) { } }
class NestedChildView : View, NestedScrollingChild { private val helper = NestedScrollingChildHelper(this) override fun onTouchEvent(e: MotionEvent): Boolean { when (e.action) { MotionEvent.ACTION_DOWN -> { helper.startNestedScroll(View.SCROLL_AXIS_VERTICAL) } MotionEvent.ACTION_MOVE -> { helper.dispatchNestedScroll(0, dyConsumed, 0, dyUnconsumed, null) } MotionEvent.ACTION_UP -> { helper.stopNestedScroll() } } return super.onTouchEvent(e) } }
|