car/src/main/java/androidx/car/widget/PagedSnapHelper.java
@Override
    public int[] calculateScrollDistance(int velocityX, int velocityY) {
        int[] outDist = super.calculateScrollDistance(velocityX, velocityY);

        if (mRecyclerView == null) {
            return outDist;
        }

        RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
        if (layoutManager == null || layoutManager.getChildCount() == 0) {
            return outDist;
        }

        int lastChildPosition = isAtEnd(layoutManager) ? 0 : layoutManager.getChildCount() - 1;

        OrientationHelper orientationHelper = getOrientationHelper(layoutManager);
        View lastChild = layoutManager.getChildAt(lastChildPosition);
        float percentageVisible = getPercentageVisible(lastChild, orientationHelper);

        int maxDistance = layoutManager.getHeight();
        if (percentageVisible > 0.f) {
            // The max and min distance is the total height of the RecyclerView minus the height of
            // the last child. This ensures that each scroll will never scroll more than a single
            // page on the RecyclerView. That is, the max scroll will make the last child the
            // first child and vice versa when scrolling the opposite way.
            maxDistance -= layoutManager.getDecoratedMeasuredHeight(lastChild);
        }

        int minDistance = -maxDistance;

        outDist[0] = clamp(outDist[0], minDistance, maxDistance);
        outDist[1] = clamp(outDist[1], minDistance, maxDistance);

        return outDist;
    }
/**
     * Calculate the estimated scroll distance in each direction given velocities on both axes.
     * This method will clamp the maximum scroll distance so that a single fling will never scroll
     * more than one page.
     *
     * @param velocityX Fling velocity on the horizontal axis.
     * @param velocityY Fling velocity on the vertical axis.
     * @return An array holding the calculated distances in x and y directions respectively.
     */
Calculate the estimated scroll distance in each direction given velocities on both axes.
This method will clamp the maximum scroll distance so that a single fling will never scroll
more than one page.

@param velocityX Fling velocity on the horizontal axis.
@param velocityY Fling velocity on the vertical axis.
@return An array holding the calculated distances in x and y directions respectively.
Calculate the estimated scroll distance in each direction given velocities on both axes . This method will clamp the maximum scroll distance so that a single fling will never scroll more than one page . @param velocityX Fling velocity on the horizontal axis . @param velocityY Fling velocity on the vertical axis . @return An array holding the calculated distances in x and y directions respectively .
@Override
    public int[] calculateScrollDistance(int velocityX, int velocityY) {
        int[] outDist = super.calculateScrollDistance(velocityX, velocityY);
        if (mRecyclerView == null) {
            return outDist;
        }
        RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
        if (layoutManager == null || layoutManager.getChildCount() == 0) {
            return outDist;
        }
        int lastChildPosition = isAtEnd(layoutManager) ? 0 : layoutManager.getChildCount() - 1;
        OrientationHelper orientationHelper = getOrientationHelper(layoutManager);
        View lastChild = layoutManager.getChildAt(lastChildPosition);
        float percentageVisible = getPercentageVisible(lastChild, orientationHelper);
        int maxDistance = layoutManager.getHeight();
        if (percentageVisible > 0.f) {
            maxDistance -= layoutManager.getDecoratedMeasuredHeight(lastChild);
        }
        int minDistance = -maxDistance;
        outDist[0] = clamp(outDist[0], minDistance, maxDistance);
        outDist[1] = clamp(outDist[1], minDistance, maxDistance);
        return outDist;
    }
@ Override public int [ ] calculateScrollDistance ( int velocityX , int velocityY ) { int [ ] outDist = super . calculateScrollDistance ( velocityX , velocityY ) ; if ( mRecyclerView == null ) { return outDist ; } RecyclerView . LayoutManager layoutManager = mRecyclerView . getLayoutManager ( ) ; if ( layoutManager == null || layoutManager . getChildCount ( ) == 0 ) { return outDist ; } int lastChildPosition = isAtEnd ( layoutManager ) ? 0 : layoutManager . getChildCount ( ) - 1 ; OrientationHelper orientationHelper = getOrientationHelper ( layoutManager ) ; View lastChild = layoutManager . getChildAt ( lastChildPosition ) ; float percentageVisible = getPercentageVisible ( lastChild , orientationHelper ) ; int maxDistance = layoutManager . getHeight ( ) ; if ( percentageVisible > 0.f ) { maxDistance -= layoutManager . getDecoratedMeasuredHeight ( lastChild ) ; } int minDistance = - maxDistance ; outDist [ 0 ] = clamp ( outDist [ 0 ] , minDistance , maxDistance ) ; outDist [ 1 ] = clamp ( outDist [ 1 ] , minDistance , maxDistance ) ; return outDist ; }
Calculate the estimated scroll distance in each direction given velocities on both axes.
Calculate the estimated scroll distance in each direction given velocities on both axes .
// The max and min distance is the total height of the RecyclerView minus the height of // the last child. This ensures that each scroll will never scroll more than a single // page on the RecyclerView. That is, the max scroll will make the last child the // first child and vice versa when scrolling the opposite way.