不会触发OnTouchListener

时间:2017-09-30 09:41:04

标签: android ontouchlistener

我在其中一条线上设置了一个断点,但它似乎永远不会在断点处停止,我假设基于它只是没有触发,这里是代码:

final ImageView imageViewRoomButton = (ImageView) findViewById(R.id.imageView9);

final GestureDetector gdt = new GestureDetector(new GestureListener());

imageViewRoomButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            gdt.onTouchEvent(event);
            return true;
        }
    });


private class GestureListener extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onDown(MotionEvent event) {



        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        Toast toast1 = Toast.makeText(getApplicationContext(), "you just swiped up", Toast.LENGTH_LONG);
        toast1.show();

        if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            return true; // Right to left
        }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            return true; // Left to right
        }

        if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {


            return true; // Bottom to top
        }  else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            return true; // Top to bottom
        }
        return true;
    }
}

我在onFling,onDown和onTouch中都设置了断点,没有任何反应。

有什么建议吗?

0 个答案:

没有答案