问题
The documentation say this about that:
A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly.
So i have done the override of onTouchEvent function in my activity:
@Override
public boolean onTouchEvent(MotionEvent MEvent)
{
motionaction = MEvent.getAction();
if(motionaction == MotionEvent.ACTION_DOWN)
{
System.out.println("DEBUG MESSAGE POINTER1 " + MEvent.getActionIndex() );
}
if(motionaction == MotionEvent.ACTION_POINTER_DOWN)
{
System.out.println("DEBUG MESSAGE POINTER2 " + MEvent.getActionIndex() );
}
}
Unfortunately the second if is never entered. The activity contains 2 view with 2 OnTouchListener, i know that onTouchEvent is called only if the view of the activity don't consume the event so i tried to return false in the listener and in that way i can recognize only the first finger touch but this avoid the listener to receive the ACTION_UP event and don't allow me to recognize the second finger touch. I also tried to return true in the listener but after manually invoke the onTouchEvent function but this allow me to recognize only the first finger touch too.
What's wrong in my code ?
回答1:
I believe your code is missing the masking operation like:
switch (motionaction & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
}
This code should be able to check for ACTION_POINTER_DOWN.
Good luck & tell us what happens.
Tommy Kwee
来源:https://stackoverflow.com/questions/11350064/android-how-to-handle-two-finger-touch