我正在编写一个代码来根据这里的建议处理触摸事件。我使用 ViewPager 作为 ViewGroup 和 ListView(我知道#thisbad)作为片段的子视图。
这就是我想要实现的目标:
- 检测子视图上的多点触控事件
- 然后将触摸控制传递给父母
但是在将侦听器事件从子视图传递到父视图时,它会给出以下错误:
E/AndroidRuntime(11414): java.lang.IllegalArgumentException:pointerIndex out of range
E/AndroidRuntime(11414): at android.view.MotionEvent.nativeGetAxisValue(Native Method)
E/AndroidRuntime(11414): at android.view.MotionEvent.getX(MotionEvent.java:1979)
E/AndroidRuntime(11414): at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
E/AndroidRuntime(11414): at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
E/AndroidRuntime(11414): at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
E/AndroidRuntime(11414): at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:1971) ..................
E/AndroidRuntime(11414): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5588)
E/AndroidRuntime(11414): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5634)
E/AndroidRuntime(11414): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
E/AndroidRuntime(11414): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
E/AndroidRuntime(11414): at android.view.Choreographer.doFrame(Choreographer.java:542)
我检查了其他一些帖子有同样的问题,比如和这里,但他们都使用指针索引来做一些事情,但在我的情况下,我现在只是将控制权传递给父(ViewPager)视图。
分析:这里我检查了使用FrameLayout而不是Child Fragment中的Listview。并且它没有任何提到的问题..但不适用于 ListView。
设备信息: OS V4.4.4 S5。
任何建议!