trying to animate my drawable

Problems with Canvas, OpenGL, etc...

trying to animate my drawable

Postby stece » Tue Jul 06, 2010 6:31 pm

Dear Android fanatics

I'm experimenting with 2D graphics. I made a View on which a OvalShape is drawn.
While using a Thread I try to move it from left to right. I can't get this to work. It draws the OvalShape but I don't know how to force a redraw in my Thread after the X-coord is changed. Also I call for a Dialog (a custom class I made for other applications, which I know that it works). But when It gets to the line from the dialog, the application force closes. The context variable contains "getApplicationContext()" from the main Activity.

Any ideas and tips?


Code: Select all
public class MyDrawView extends View {

   private ShapeDrawable myDrawable;
   private int x = 5;
   private int y = 5;
   private int width = 100;
   private int height = 35;
   private Context context;
   
   public MyDrawView(Context pContext) {
      super(pContext);
      context = pContext;
      myDrawable = new ShapeDrawable(new OvalShape());
      myDrawable.getPaint().setColor(0xff74AC23);
      myDrawable.setBounds(x, y, x + width, y + height);
      new MyThread().start();
   }

   @Override
   protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      myDrawable.draw(canvas);
   }

   private class MyThread extends Thread {
      public void run() {
         for (int i = 0; i < 10; i++) {
            x += 5;
            Dialog dia = new Dialog(context);
            dia.showAlert("TEST: " + x);
            try {
               sleep(1000);
            } catch (InterruptedException e) {
            }
         }
      }
   }
}
User avatar
stece
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Wed Apr 21, 2010 10:50 am
Location: Belgium

Top

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 4 guests