Guest User

Animação - Círculo de tempo

a guest
Sep 16th, 2011
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.content.Context;
  3. import android.graphics.Canvas;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.graphics.Rect;
  7. import android.graphics.RectF;
  8. import android.os.Bundle;
  9. import android.os.Handler;
  10. import android.view.View;
  11.  
  12. public class ActivityTeste extends Activity implements Runnable {
  13.    
  14.     int angle = 1;
  15.    
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         Handler handler = new Handler();
  20.         for(int i = 0;i < 360;i++) {
  21.             handler.postDelayed(this, 100 * i/10);
  22.         }
  23.     }
  24.    
  25.     private class Teste extends View {
  26.         int angle;
  27.        
  28.         public Teste(Context context, int angle) {
  29.             super(context);
  30.             this.angle = angle;
  31.         }
  32.        
  33.         @Override
  34.         protected void onDraw(Canvas canvas) {
  35.             super.onDraw(canvas);
  36.            
  37.             Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  38.             paint.setColor(Color.GREEN);
  39.             paint.setAlpha(50);
  40.             RectF rect = new RectF(new Rect(0, 0, 300, 300));
  41.             canvas.drawArc(rect, 270, angle, true, paint);
  42.             invalidate();
  43.         }
  44.     }
  45.  
  46.     @Override
  47.     public void run() {
  48.         setContentView(new Teste(this, this.angle++));
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment