shui知道

偶尔会要用到这个,目前我只试过第一种方式是ok,其他几个没有测试。

摘抄内容

  1. give it a ACTION_CANCEL touchEvent, can stop the fling. it is easy.
listView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),  SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0));
  1. You can prevent flinging for ListViews in API 8 by overriding onTouchEvent and calling smoothScrollBy.
case:smoothScrollBy(0,0);

  1. reflection(反射
    static 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) {
                }
            }
        }
    }

摘抄来源

  1. 停止ListView滑动-Android

相关文章

暂无评论

none
暂无评论...