<i id='ESlOr'><tr id='ESlOr'><dt id='ESlOr'><q id='ESlOr'><span id='ESlOr'><b id='ESlOr'><form id='ESlOr'><ins id='ESlOr'></ins><ul id='ESlOr'></ul><sub id='ESlOr'></sub></form><legend id='ESlOr'></legend><bdo id='ESlOr'><pre id='ESlOr'><center id='ESlOr'></center></pre></bdo></b><th id='ESlOr'></th></span></q></dt></tr></i><div id='ESlOr'><tfoot id='ESlOr'></tfoot><dl id='ESlOr'><fieldset id='ESlOr'></fieldset></dl></div>
      • <bdo id='ESlOr'></bdo><ul id='ESlOr'></ul>

      <small id='ESlOr'></small><noframes id='ESlOr'>

      <tfoot id='ESlOr'></tfoot>
        <legend id='ESlOr'><style id='ESlOr'><dir id='ESlOr'><q id='ESlOr'></q></dir></style></legend>

        ViewPager:java.lang.IllegalArgumentException:pointerIndex 超出

        时间:2023-10-04
        <legend id='1xg42'><style id='1xg42'><dir id='1xg42'><q id='1xg42'></q></dir></style></legend>

          <i id='1xg42'><tr id='1xg42'><dt id='1xg42'><q id='1xg42'><span id='1xg42'><b id='1xg42'><form id='1xg42'><ins id='1xg42'></ins><ul id='1xg42'></ul><sub id='1xg42'></sub></form><legend id='1xg42'></legend><bdo id='1xg42'><pre id='1xg42'><center id='1xg42'></center></pre></bdo></b><th id='1xg42'></th></span></q></dt></tr></i><div id='1xg42'><tfoot id='1xg42'></tfoot><dl id='1xg42'><fieldset id='1xg42'></fieldset></dl></div>

            <tbody id='1xg42'></tbody>

          • <tfoot id='1xg42'></tfoot>
              <bdo id='1xg42'></bdo><ul id='1xg42'></ul>

                <small id='1xg42'></small><noframes id='1xg42'>

                  本文介绍了ViewPager:java.lang.IllegalArgumentException:pointerIndex 超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写一个代码来根据建议 这里.我使用 ViewPager 作为 ViewGroup 和 ListView(我知道 #thisbad)作为 Fragment 的子视图.

                  这就是我想要实现的目标:

                  1. 在子视图上检测多点触控事件
                  2. 然后将触摸控制传递给父母

                  但是在将侦听器事件从子视图传递到父视图时,它会给出以下错误:

                  E/AndroidRuntime(11414): java.lang.IllegalArgumentException:pointerIndex 超出范围E/AndroidRuntime(11414):在 android.view.MotionEvent.nativeGetAxisValue(Native Method)E/AndroidRuntime(11414):在 android.view.MotionEvent.getX(MotionEvent.java:1979)E/AndroidRuntime(11414):在 android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)E/AndroidRuntime(11414):在 android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)E/AndroidRuntime(11414):在 android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)E/AndroidRuntime(11414): 在 android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:1971) .....E/AndroidRuntime(11414):在 android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5588)E/AndroidRuntime(11414):在 android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5634)E/AndroidRuntime(11414):在 android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)E/AndroidRuntime(11414):在 android.view.Choreographer.doCallbacks(Choreographer.java:574)E/AndroidRuntime(11414):在 android.view.Choreographer.doFrame(Choreographer.java:542)

                  我检查了其他一些帖子有同样的问题 like 和 这里 但他们都在使用指针索引来做一些事情,但在我的情况下,我现在只是将控制权传递给父(ViewPager)视图.p>

                  分析:这里我检查了使用FrameLayout而不是子片段中的Listview.并且它没有任何提到的问题..但不是 ListView.

                  设备信息: OS V4.4.4 S5.

                  任何建议!

                  解决方案

                  不知道为什么 MotionEventCompat 会调用 MotionEventCompatEclair,我在代码中看到,有一个 MotionEventCompatHoneycomb 重载,但是我在 Moto XT1040 上遇到了同样的问题在安卓 4.4.4 中.

                  我的解决方案是创建我的 ViewPager 版本(我只是从 android 源代码复制了整个类)并在方法 onInterceptTouchEvent(MotionEvent ev) 的情况下 MotionEvent.ACTION_MOVE 更改初始行:

                  final int activePointerId = mActivePointerId;if (activePointerId == INVALID_POINTER) {//如果我们没有有效的 id,则触地不在内容上.休息;}final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);最终浮点 x = MotionEventCompat.getX(ev, pointerIndex);最终浮点 dx = x - mLastMotionX;最终浮点 xDiff = Math.abs(dx);最终浮点 y = MotionEventCompat.getY(ev, pointerIndex);最终浮点 yDiff = Math.abs(y - mInitialMotionY);

                  到:

                  final int activePointerId = mActivePointerId;if (activePointerId == INVALID_POINTER) {//如果我们没有有效的 id,则触地不在内容上.休息;}final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);最终浮点 x = ev.getX(pointerIndex);最终浮点 dx = x - mLastMotionX;最终浮点 xDiff = Math.abs(dx);最终浮点 y = ev.getY(pointerIndex);最终浮点 yDiff = Math.abs(y - mInitialMotionY);

                  唯一的变化是x和y变量,我改为直接调用MotionEvent getX和getY方法,忽略MotionEventCompat.

                  我的应用程序最低 api 14,如果您支持 14 之前的内容,我建议您从您的版本中调用最接近的 MotionEventCompat.您只需要阻止调用 MotivoEventCompatEclair 版本即可.

                  I am writing an code to handle touch event based on what suggested here. I am using ViewPager as an ViewGroup and ListView(I know #thisbad) as child view of Fragment.

                  This is what I wanted to achieve:

                  1. Detect multitouch event on child view
                  2. then pass touch control to parent

                  but While passing listener event from child View to Parent view it giving following error:

                  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)
                  

                  I checked with some other post have same issue like and here but all they are using Pointer indexing to do somehting but in my case I am just passing control to parent(ViewPager) view now.

                  Analysis: Here I checked to use FrameLayout instead to Listview in Child Fragment. and it's working without any mentioned issue..but not with ListView.

                  Device Info: OS V4.4.4 S5.

                  Any suggestion!

                  解决方案

                  I don't know why MotionEventCompat is calling MotionEventCompatEclair, as I saw in the code, there are a MotionEventCompatHoneycomb overload, but I had the same problem with Moto XT1040 in android 4.4.4.

                  The solution for me was create my version of ViewPager(I just copied the entire class from android source) and in the method onInterceptTouchEvent(MotionEvent ev) in the case of MotionEvent.ACTION_MOVE change the initial lines from:

                  final int activePointerId = mActivePointerId;
                  if (activePointerId == INVALID_POINTER) {
                      // If we don't have a valid id, the touch down wasn't on content.
                      break;
                  }
                  
                  final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
                  final float x = MotionEventCompat.getX(ev, pointerIndex);
                  final float dx = x - mLastMotionX;
                  final float xDiff = Math.abs(dx);
                  final float y = MotionEventCompat.getY(ev, pointerIndex);
                  final float yDiff = Math.abs(y - mInitialMotionY);
                  

                  to:

                  final int activePointerId = mActivePointerId;
                  if (activePointerId == INVALID_POINTER) {
                      // If we don't have a valid id, the touch down wasn't on content.
                      break;
                  }
                  
                  final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
                  final float x = ev.getX(pointerIndex);
                  final float dx = x - mLastMotionX;
                  final float xDiff = Math.abs(dx);
                  final float y = ev.getY(pointerIndex);
                  final float yDiff = Math.abs(y - mInitialMotionY);
                  

                  The only change was in the x and y variables, I changed to call the MotionEvent getX and getY method directly, ignoring the MotionEventCompat.

                  My app was minimum api 14, if you are supporting something previous from 14, I suggest to you call the closest MotionEventCompat from your version. You just need to prevent from calling the MotivoEventCompatEclair version.

                  这篇关于ViewPager:java.lang.IllegalArgumentException:pointerIndex 超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在片段内实现viewpager? 下一篇:在 ViewPager Fragments 中使用 Master/Detail 模板(下载链接)

                  相关文章

                1. <small id='w6rm3'></small><noframes id='w6rm3'>

                      <bdo id='w6rm3'></bdo><ul id='w6rm3'></ul>
                    <legend id='w6rm3'><style id='w6rm3'><dir id='w6rm3'><q id='w6rm3'></q></dir></style></legend>

                      <i id='w6rm3'><tr id='w6rm3'><dt id='w6rm3'><q id='w6rm3'><span id='w6rm3'><b id='w6rm3'><form id='w6rm3'><ins id='w6rm3'></ins><ul id='w6rm3'></ul><sub id='w6rm3'></sub></form><legend id='w6rm3'></legend><bdo id='w6rm3'><pre id='w6rm3'><center id='w6rm3'></center></pre></bdo></b><th id='w6rm3'></th></span></q></dt></tr></i><div id='w6rm3'><tfoot id='w6rm3'></tfoot><dl id='w6rm3'><fieldset id='w6rm3'></fieldset></dl></div>
                      <tfoot id='w6rm3'></tfoot>