onSwipeleft到右边我得到标签ScrollView和无效的pointerId = -1 onTouchEvent

  发布于 2023-02-07 11:11

我在屏幕上左右滑动有一个事件,但TouchEvent上有一个无效的pointerId = -1,在某些手机上崩溃应用程序这里是我使用的类

   public class OnSwipeTouchListener implements OnTouchListener {
    private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
     @Override
     public boolean onTouch(View arg0, MotionEvent arg1) {
    // TODO Auto-generated method stub
    return gestureDetector.onTouchEvent(arg1);
     }
    private final class GestureListener extends SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 100;
    private static final int SWIPE_VELOCITY_THRESHOLD = 100;


        @Override
        public boolean onDown(MotionEvent e) {
         return true;
        }

       @Override
       public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)  {
          boolean result = false;
          try {
              float diffY = e2.getY() - e1.getY();
              float diffX = e2.getX() - e1.getX();

             if (Math.abs(diffX) > Math.abs(diffY)) {
                  if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffX > 0) {
                        onSwipeRight();
                    } else {
                        onSwipeLeft();
                    }
                }
              } 
         } catch (Exception exception) {
            exception.printStackTrace();
        }
        return result;
    }


}

      public void onSwipeRight() {
      }

      public void onSwipeLeft() {
      }


}

我得到这个错误java.lang.IllegalArgumentException:pointerIndex超出范围

在我的主要活动课中,我使用这个

fullView = (View)findViewById(R.id.fullview);
   fullView.setOnTouchListener(imageViewSwiped);  -> inside onCreate method

在onCreate之后我使用它

     OnTouchListener imageViewSwiped = new OnSwipeTouchListener()
      {
     public void onSwipeRight() {

            minusOne();
        }
        public void onSwipeLeft() {
           // Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show();
            plusOne();
        }
};

denza.. 9

我所做的就是评论这个覆盖

     /*

    @Override
    public boolean onDown(MotionEvent e) {
     return true;
    }

      */

一切都很完美......

1 个回答
  • 我所做的就是评论这个覆盖

         /*
    
        @Override
        public boolean onDown(MotionEvent e) {
         return true;
        }
    
          */
    

    一切都很完美......

    2023-02-07 11:14 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有