我在哪里可以将ACTION_UP放在我的代码中以便它可以工作?

时间:2014-06-25 10:57:49

标签: java android touch

我有一个圆圈的代码显示onTouchListener并在屏幕上用手指按住。现在我正在努力让手指从屏幕上取下时消失。我很确定ACTION_UP:是我需要的。我只是不知道如何实现它。

这是我想要进入ACTION_UP

的代码
   paint.setARGB(1, r, g, b);         

到目前为止,这是相关代码:

 public void onDraw(Canvas canvas)
{
    paint.setARGB(255, r, g, b);

    //drawing the circle
    canvas.drawCircle(x,y,radius,paint);

}

public boolean onTouch(View view,MotionEvent event)
{
    x=(int)event.getX()-(radius/2);      //logic to plot the circle in exact touch place
    y=(int)event.getY()-(radius/2);
      //System.out.println("X,Y:"+"x"+","+y);      
    randColor();  //color of circle
    invalidate();    
    return true;
        //where I think I need to put ACTION_UP...
}

1 个答案:

答案 0 :(得分:1)

它的工作原理如下:

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                Your code...
            }
            return false;
        }
相关问题