Stop ListView Scrolling Animation

I have ListViewabout 100 entries. When the user rolls from bottom to top, he starts scrolling and continues to scroll, even if his finger no longer touches the display.

Is there a way to stop the scroll animation at this point?

+3
source share
5 answers

Well, of course, there is a way to do this. But the point is whether it is really advisable to do this, in my opinion.

A list is a standard Android control that behaves across all applications. Therefore, I would be surprised if I found a list that would not conduct the same in your application. You can stop the throw by returning your finger to the screen at any time.

, , touch. , , - ListView (ListView Android 1.6).

+3

Android (AbsListView), ACTION_CANCEL touchEvent, . .

listView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0));
+15

Pompe de velo, smoothScrollToPosition() API 8, .

, , . , () , . , , . , , .

class StopListFling {

    private static Field mFlingEndField = null;
    private static Method mFlingEndMethod = null;

    static {
        try {
            mFlingEndField = AbsListView.class.getDeclaredField("mFlingRunnable");
            mFlingEndField.setAccessible(true);
            mFlingEndMethod = mFlingEndField.getType().getDeclaredMethod("endFling");
            mFlingEndMethod.setAccessible(true);
        } catch (Exception e) {
            mFlingEndMethod = null;
        }
    }

    public static void stop(ListView list) {
        if (mFlingEndMethod != null) {
            try {
                mFlingEndMethod.invoke(mFlingEndField.get(list));
            } catch (Exception e) {
            }
        }
    }
}
+9

ListViews API 8 onTouchEvent smoothScrollBy.

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_UP:
        this.smoothScrollBy(0, 0);
        break;
    }
    return super.onTouchEvent(ev);
}

0px.

+3

, , fling - , .

. , .

OnScrollListener ListView onScrollStateChanged(), , SCROLL_STATE_FLING. , , , ListView getFirstVisiblePosition() smoothScrollToPosition(), getFirstVisiblePosition() .

0

All Articles