Android Touch事件指针向下

val*_*lll 3 android touch

嗨,我想检测两个手指何时触摸屏幕:

   case MotionEvent.ACTION_POINTER_2_DOWN: {

    twoFing=true;
    return true;
}
Run Code Online (Sandbox Code Playgroud)

问题是:

public static final int ACTION_POINTER_2_DOWN
Run Code Online (Sandbox Code Playgroud)

医生说,他被贬低了:

*getActionMasked()的常量:非主指针已经关闭.使用getActionIndex()来检索已更改的指针的索引.索引编码在getAction()返回的未屏蔽操作的ACTION_POINTER_INDEX_MASK位中.*

但我不明白如何使用它...我怎么能检测到有2个指针?如果我尝试getPointerIndex(),ActionUP和DOwn总是说只有一个指针

非常感谢

编辑:我在这里发布完整的代码,以更清楚地了解问题.我的代码正在工作,因为ACTION_POINTER_2_DOWN是一个弃用的值我想用其他东西替换它,但我不知道如何.

@SuppressWarnings("deprecation")
public boolean onTouch(View v, MotionEvent event) {

switch(event.getAction()){

case MotionEvent.ACTION_DOWN : {
     Log.i(TAG, "Action Down");
    downX = event.getX(0);
    downY = event.getY(0);
    return true;
}

case MotionEvent.ACTION_UP: {


    upX = event.getX(0);
    upY = event.getY(0);

    float deltaX = downX - upX;
    float deltaY = downY - upY;
    Log.i(TAG, "Action UP deltaX="+deltaX+", deltaY="+deltaY);



    // swipe vertical?
    if(Math.abs(deltaY) > MIN_DISTANCE && twoFing){
        twoFing=false;

        // top or down
        if(deltaY < 0 ) 
        { 
            if(slide.zoom==1) 
            slide.zoom=0; 
        Log.i(TAG, "Going Down zooming in");
            //return true; 
        }
        if((deltaY > 0) )
        { 

            if(slide.zoom==0) 
                slide.zoom=1;  
            Log.i(TAG, "Going up zoomig out");
            //return true;
        }

        return true;
    }
    // swipe horizontal?
  if(Math.abs(deltaX) > MIN_DISTANCE && !twoFing){

        // left or right
        if(deltaX < 0) { this.slideToTheLeft(); return true; }
        if(deltaX > 0) { this.slideToTheRight(); return true; }
        return true;
    }

  return false;
}

case MotionEvent.ACTION_POINTER_2_DOWN: {

    twoFing=true; //inform that the touch was made with 2 fingers
    Log.i(TAG, "Action Second pointer down");

    return true;
}
}
return false;
Run Code Online (Sandbox Code Playgroud)

}

And*_*rea 6

我现在正在研究指针.您想要切换如下

 switch(event.getAction() & MotionEvent.ACTION_MASK);
     case MotionEvent.ACTION_POINTER_DOWN:
Run Code Online (Sandbox Code Playgroud)

ACTION_DOWN是第一个手指向下.ACTION_POINTER_DOWN是第二根手指.

有关相当清晰的说明,请参阅http://www.vogella.com/articles/AndroidTouch/article.html.