0

Original Question: I am trying to draw rectangles on the canvas one after the other. I would like to pause for a second before drawing each object. How would I implement this feature?


EDIT: This is the code that I have working so far. Not sure if this is the best practice. Suggest a better way if you know one.

boolean stopAnimation = false;

int currentRectangle = 0;
Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
    invalidate();
    System.out.println("redraw"+currentRectangle);
    currentRectangle++;
        if(currentRectangle>2){
          stopAnimation = true;
        }
};
};

public void onDraw(final Canvas canvas) {
    final Rect currentRect = new Rect(a, 0, b, c);
    canvas.drawRect(currentRect, paint); //wait a lil bit
    canvas.drawRect(newRect, paint);
}

public void run() {
   while (!stopAnimation) {
         try {
             Thread.sleep(200);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
             handler.sendEmptyMessage(0);
   }
}
industrychanger
  • 563
  • 1
  • 9
  • 21

1 Answers1

0

I believe this would solve your answer:

How to pause for 5 seconds before drawing the next thing on Android?

If you need specifics please reply and I would be happy to help.

Community
  • 1
  • 1
Bedimindtricks
  • 113
  • 1
  • 7
  • I checked out that post and gathered a few things together. What I got working so far can be seen in the EDIT I posted above. Let me know if you know of a better way. – industrychanger Dec 07 '13 at 03:38