FileDocCategorySizeDatePackage
ListViewAutoScrollHelper.javaAPI DocAndroid 5.1 API2959Thu Mar 12 22:22:56 GMT 2015android.support.v4.widget

ListViewAutoScrollHelper

public class ListViewAutoScrollHelper extends AutoScrollHelper
An implementation of {@link AutoScrollHelper} that knows how to scroll through a {@link ListView}.

Fields Summary
private final android.widget.ListView
mTarget
Constructors Summary
public ListViewAutoScrollHelper(android.widget.ListView target)

        super(target);

        mTarget = target;
    
Methods Summary
public booleancanTargetScrollHorizontally(int direction)

        // List do not scroll horizontally.
        return false;
    
public booleancanTargetScrollVertically(int direction)

        final ListView target = mTarget;
        final int itemCount = target.getCount();
        if (itemCount == 0) {
            return false;
        }

        final int childCount = target.getChildCount();
        final int firstPosition = target.getFirstVisiblePosition();
        final int lastPosition = firstPosition + childCount;

        if (direction > 0) {
            // Are we already showing the entire last item?
            if (lastPosition >= itemCount) {
                final View lastView = target.getChildAt(childCount - 1);
                if (lastView.getBottom() <= target.getHeight()) {
                    return false;
                }
            }
        } else if (direction < 0) {
            // Are we already showing the entire first item?
            if (firstPosition <= 0) {
                final View firstView = target.getChildAt(0);
                if (firstView.getTop() >= 0) {
                    return false;
                }
            }
        } else {
            // The behavior for direction 0 is undefined and we can return
            // whatever we want.
            return false;
        }

        return true;
    
public voidscrollTargetBy(int deltaX, int deltaY)

        final ListView target = mTarget;
        final int firstPosition = target.getFirstVisiblePosition();
        if (firstPosition == ListView.INVALID_POSITION) {
            return;
        }

        final View firstView = target.getChildAt(0);
        if (firstView == null) {
            return;
        }

        final int newTop = firstView.getTop() - deltaY;
        target.setSelectionFromTop(firstPosition, newTop);