Receiving onTouch and onClick events with Android

后端 未结 7 1020
滥情空心
滥情空心 2020-12-16 04:02

I have a view that need to process onTouch gestures and onClick events. What is the proper way to achieve this?

I have an onTouchListener and

相关标签:
7条回答
  • 2020-12-16 04:59

    we can use flag based implementation. where swipe/dragging we can handle in Action_Up and make the flag true and return the same. In Case of click or Tap same handle in Action_Down and set the flag false and return.

    touchAndSwipe=false;
    switch(e.getAction()){
        case MotionEvent.ACTION_MOVE:
            break;
        case MotionEvent.ACTION_DOWN:
            x1 = e.getX();
            break;
        case MotionEvent.ACTION_UP:
            x2 = e.getX();
            float diff = x2 - x1;
            if(Math.abs(delta) > 100) {
                // Swipe
                touchAndSwipe = true;
            } else {
                touchAndSwipe = false;
            }
            break;
    }
    return touchAndSwipe;
    
    0 讨论(0)
提交回复
热议问题