Java onTouch问题-x<;y don';t反应

Java onTouch问题-x<;y don';t反应,java,android,touch-event,Java,Android,Touch Event,当我使用onTouch方法时,我使用methon event.getY()为变量y2指定finger精度。但当我使用if语句时,会出现一个问题: public boolean onTouch(View v, MotionEvent event){ if(y2 <= knifeY){ //y2 = where the finger is, knifeY = where on the height a knife will be on.

当我使用onTouch方法时,我使用methon event.getY()为变量y2指定finger精度。但当我使用if语句时,会出现一个问题:

    public boolean onTouch(View v, MotionEvent event){
         if(y2 <= knifeY){
           //y2 = where the finger is, knifeY = where on the height a knife will be on.             
           knifeDown = false; 
           // The knife stops
           point--; 
           // score - 1;
           knife = BitmapFactory.decodeResource(getResources(),R.drawable.bloddyknife);
           // change picture.
           return true;
         }
    } 
public boolean onTouch(视图v,运动事件){

如果(y2您分配了
inty2=event.getY()
?因为我在任何地方都看不到它,所以必须在
onTouch()中完成

我不确定这是否是个好办法

public boolean onTouch(View v, MotionEvent event)
{
    while(event.getAction()!=MotionEvent.ACTION_CANCEL) // or here measure the pressure applied on the screen surface
    { 
       if(event.getY() <= knifeY)
       {
        knifeDOwn=false; // keep the knife down 
        point--; 
        knife = BitmapFactory.decodeResource(getResources(),R.drawable.bloddyknife); // 
         //maybe here you might stop the pointers collecting with using event.setAction(MotionEvent.ACTION_CANCEL) (or ACTION_UP) to exit the while loop, i dont know your idea for it, at this point i'm just guessing, but you still need to change the action of the event at anypoint at this code to exit the while loop.
       }
  }
  return true;
}
public boolean onTouch(视图v,运动事件)
{
while(event.getAction()!=MotionEvent.ACTION\u CANCEL)//或此处测量施加在屏幕表面上的压力
{ 

如果(event.getY()您分配了
int y2=event.getY()
?因为我在任何地方都看不到它,所以必须在
onTouch()中完成