public class

ListViewAutoScrollHelper

extends AutoScrollHelper

 java.lang.Object

androidx.core.widget.AutoScrollHelper

↳androidx.core.widget.ListViewAutoScrollHelper

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.widget.ListViewAutoScrollHelper android.support.v4.widget.ListViewAutoScrollHelper

Overview

An implementation of AutoScrollHelper that knows how to scroll through a ListView.

Summary

Fields
from AutoScrollHelperEDGE_TYPE_INSIDE, EDGE_TYPE_INSIDE_EXTEND, EDGE_TYPE_OUTSIDE, NO_MAX, NO_MIN, RELATIVE_UNSPECIFIED
Constructors
publicListViewAutoScrollHelper(ListView target)

Methods
public abstract booleancanTargetScrollHorizontally(int direction)

Override this method to return whether the target view can be scrolled horizontally in a certain direction.

public abstract booleancanTargetScrollVertically(int direction)

Override this method to return whether the target view can be scrolled vertically in a certain direction.

public abstract voidscrollTargetBy(int deltaX, int deltaY)

Override this method to scroll the target view by the specified number of pixels.

from AutoScrollHelperisEnabled, isExclusive, onTouch, setActivationDelay, setEdgeType, setEnabled, setExclusive, setMaximumEdges, setMaximumVelocity, setMinimumVelocity, setRampDownDuration, setRampUpDuration, setRelativeEdges, setRelativeVelocity
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ListViewAutoScrollHelper(ListView target)

Methods

public abstract void scrollTargetBy(int deltaX, int deltaY)

Override this method to scroll the target view by the specified number of pixels.

Parameters:

deltaX: The number of pixels to scroll by horizontally.
deltaY: The number of pixels to scroll by vertically.

public abstract boolean canTargetScrollHorizontally(int direction)

Override this method to return whether the target view can be scrolled horizontally in a certain direction.

Parameters:

direction: Negative to check scrolling left, positive to check scrolling right.

Returns:

true if the target view is able to horizontally scroll in the specified direction.

public abstract boolean canTargetScrollVertically(int direction)

Override this method to return whether the target view can be scrolled vertically in a certain direction.

Parameters:

direction: Negative to check scrolling up, positive to check scrolling down.

Returns:

true if the target view is able to vertically scroll in the specified direction.

Source

/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.core.widget;

import android.view.View;
import android.widget.ListView;

import androidx.annotation.NonNull;

/**
 * An implementation of {@link AutoScrollHelper} that knows how to scroll
 * through a {@link ListView}.
 */
public class ListViewAutoScrollHelper extends AutoScrollHelper {
    @SuppressWarnings("HidingField")
    private final ListView mTarget;

    public ListViewAutoScrollHelper(@NonNull ListView target) {
        super(target);

        mTarget = target;
    }

    @Override
    public void scrollTargetBy(int deltaX, int deltaY) {
        mTarget.scrollListBy(deltaY);
    }

    @Override
    public boolean canTargetScrollHorizontally(int direction) {
        // List do not scroll horizontally.
        return false;
    }

    @Override
    public boolean canTargetScrollVertically(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;
    }
}