强制停止ListView的滑动

强制停止ListView的滑动

没有找到现成的方法,但是可以通过反射的方式实现,具体代码如下:

Field mFlingEndField = null;
            Method mFlingEndMethod;
            try {
                mFlingEndField = AbsListView.class.getDeclaredField("mFlingRunnable");
                mFlingEndField.setAccessible(true);
                mFlingEndMethod = mFlingEndField.getType().getDeclaredMethod("endFling");
                mFlingEndMethod.setAccessible(true);
            } catch (Exception e) {
                e.printStackTrace();
                mFlingEndMethod = null;
            }
            if (mFlingEndMethod != null) {
                try {
                    mFlingEndMethod.invoke(mFlingEndField.get(this));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

我也是从网上找到的,本来想转载,太久了已经忘记是从哪看到的了。

你可能感兴趣的:(Android-常用技巧)