shui知道
偶尔会要用到这个,目前我只试过第一种方式是ok,其他几个没有测试。
摘抄内容
- 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));
- You can prevent flinging for ListViews in API 8 by overriding onTouchEvent and calling smoothScrollBy.
case:smoothScrollBy(0,0);
- 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) { } } } }
摘抄来源
© 版权声明