FileDocCategorySizeDatePackage
ScrollbarHelper.javaAPI DocAndroid 5.1 API4231Thu Mar 12 22:22:56 GMT 2015android.support.v7.widget

ScrollbarHelper

public class ScrollbarHelper extends Object
A helper class to do scroll offset calculations.

Fields Summary
Constructors Summary
Methods Summary
static intcomputeScrollExtent(RecyclerView.State state, OrientationHelper orientation, android.view.View startChild, android.view.View endChild, RecyclerView.LayoutManager lm, boolean smoothScrollbarEnabled)

param
startChild View closest to start of the list. (top or left)
param
endChild View closest to end of the list (bottom or right)

        if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null ||
                endChild == null) {
            return 0;
        }
        if (!smoothScrollbarEnabled) {
            return Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1;
        }
        final int extend = orientation.getDecoratedEnd(endChild)
                - orientation.getDecoratedStart(startChild);
        return Math.min(orientation.getTotalSpace(), extend);
    
static intcomputeScrollOffset(RecyclerView.State state, OrientationHelper orientation, android.view.View startChild, android.view.View endChild, RecyclerView.LayoutManager lm, boolean smoothScrollbarEnabled, boolean reverseLayout)

param
startChild View closest to start of the list. (top or left)
param
endChild View closest to end of the list (bottom or right)

        if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null ||
                endChild == null) {
            return 0;
        }
        final int minPosition = Math.min(lm.getPosition(startChild),
                lm.getPosition(endChild));
        final int maxPosition = Math.max(lm.getPosition(startChild),
                lm.getPosition(endChild));
        final int itemsBefore = reverseLayout
                ? Math.max(0, state.getItemCount() - maxPosition - 1)
                : Math.max(0, minPosition);
        if (!smoothScrollbarEnabled) {
            return itemsBefore;
        }
        final int laidOutArea = Math.abs(orientation.getDecoratedEnd(endChild) -
                orientation.getDecoratedStart(startChild));
        final int itemRange = Math.abs(lm.getPosition(startChild) -
                lm.getPosition(endChild)) + 1;
        final float avgSizePerRow = (float) laidOutArea / itemRange;

        return Math.round(itemsBefore * avgSizePerRow + (orientation.getStartAfterPadding()
                - orientation.getDecoratedStart(startChild)));
    
static intcomputeScrollRange(RecyclerView.State state, OrientationHelper orientation, android.view.View startChild, android.view.View endChild, RecyclerView.LayoutManager lm, boolean smoothScrollbarEnabled)

param
startChild View closest to start of the list. (top or left)
param
endChild View closest to end of the list (bottom or right)

        if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null ||
                endChild == null) {
            return 0;
        }
        if (!smoothScrollbarEnabled) {
            return state.getItemCount();
        }
        // smooth scrollbar enabled. try to estimate better.
        final int laidOutArea = orientation.getDecoratedEnd(endChild) -
                orientation.getDecoratedStart(startChild);
        final int laidOutRange = Math.abs(lm.getPosition(startChild) -
                lm.getPosition(endChild))
                + 1;
        // estimate a size for full list.
        return (int) ((float) laidOutArea / laidOutRange * state.getItemCount());