Android multitouch! hack anyone?

前端 未结 3 546
深忆病人
深忆病人 2020-12-16 02:17

I have to let this slip for now as a purely academic issue but i would very much like to see a solution in near time.

Due to the way that Android handles multitouch

相关标签:
3条回答
  • 2020-12-16 02:51
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if(ev.getPointerCount() > 1) return false;
        return super.dispatchTouchEvent(ev);
    }
    

    insert this on activity or view

    0 讨论(0)
  • 2020-12-16 02:53

    The best solution here is to put

    android:splitMotionEvents = false 
    

    inside LinearLayout or any Layout your view (Button, TextView, etc) is.

    -cheers happy codings

    0 讨论(0)
  • 2020-12-16 03:16

    You need to override onInterceptTouchEvent as well to capture motion events. When you return true from onInterceptTouchEvent, all subsequent events (whether inside your view bounds or not) are captured in calls to onTouchEvent up until (and including) the point where the last pointer goes up.

    Traditionally, you put enough logic in onInterceptTouchEvent to determine that a pointer has gone down, AND that it has moved beyond some threshold before returning true, but that depends on whether you want to support drag in horizontal and/or vertical directions in parent views. If an ACTION_POINTER_DOWN event is sufficient to trigger the capture, then you can return true immediately.

    0 讨论(0)
提交回复
热议问题