如何在android中撤消

时间:2012-01-27 13:01:05

标签: android

 onTouch(MotionEvent event){
 int x = (int) event.getX();
 int y = (int) event.getY();

 if(event.getAction==MotionEvent.DOWN){
       temp_point = new ArrayList<Point>();
       temp_point.add(new Point(x,y);
 }else if(event.getAction==MotionEvent.MOVE){
       if(temp_point!=null)
          temp_point.add(new Point(x,y);
 }else if(event.getAction==MotionEvent.UP){
       mainPoint.add(temp_point);
       temp_point = null;
 }
 return true;

}

我正在使用画布进行绘画。我能够擦除油漆,但是我无法撤消上一次油漆。

2 个答案:

答案 0 :(得分:0)

如果你对在这种情况下实现撤销/重做感兴趣,你应该查看Command Pattern

它与Android本身无关。您可以自行实施该功能。

答案 1 :(得分:0)

您可以将paint对象保存在一个数组中,如paint []。 我试着粗略地弄清楚它。

Paint [] paint = new Paint [counter] // counter是你想要的对象数。

当你想要将新的绘画对象应用到画布时,数组的对象将创建新的并且并行计数器会增加...

当你撤消时,你的计数器会减少,这样你就可以获得前一个绘画对象,你可以应用于画布,这意味着它可以撤消画布..