[摘]停止ListView滑动-Android

Android 1年前 (2020) 125la.com站长
21 0 0
站长公众号

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

站长公众号
版权声明:125la.com站长 发表于 2020年8月7日 下午12:29 。
转载请注明: [摘]停止ListView滑动-Android | 125啦读书导航

相关文章

站长公众号

暂无评论

暂无评论...