fun fling(velocityX: Int, velocityY: Int) { if (getChildCount() > 0) { val height: Int = getHeight() - getPaddingBottom() - getPaddingTop() val bottom: Int = getChildAt(0).getHeight() val width: Int = getWidth() - getPaddingRight() - getPaddingLeft() val right: Int = getChildAt(0).getWidth() mScroller.fling( getScrollX(), getScrollY(), velocityX, velocityY, 0, right - width, 0, bottom - height ) val movingDown = velocityY > 0 val movingRight = velocityX > 0 var newFocused: View = findFocusableViewInMyBounds( movingRight, mScroller.getFinalX(), movingDown, mScroller.getFinalY(), findFocus() ) if (newFocused == null) { newFocused = this } if (newFocused !== findFocus() && newFocused.requestFocus(if (movingDown) View.FOCUS_DOWN else View.FOCUS_UP)) { mTwoDScrollViewMovedFocus = true mTwoDScrollViewMovedFocus = false } awakenScrollBars(mScroller.getDuration()) invalidate() } }
Fling the scroll view