Lucky_girl Lucky_girl - 5 months ago 19
Java Question

Animation in Android

I have a Canvas, on which I draw circles using drawCircle(), what I need is to animate the increasing of the radius of these circles. As far as I understood it's possible to do this using VectorDrawable and AnimatedVectorDrawable. Can anyone provide example how to do it? or maybe exist other ways how better to do it?

Answer

I decided to use Matrix to animate circles in the Canvas.

 private int x;
 private int y;
 private Canvas tempCanvas;
 private Matrix matrix = new Matrix();
 private Path path = new Path();

 animateCircle(){
 Paint myPaint = new Paint();
 myPaint.setAntiAlias(true);
 myPaint.setColor(Color.RED);
 path.addCircle(x, y, 10, Path.Direction.CW);
 //increasing radius of the certain circle 
 matrix.setScale(1.1f, 1.1f, x-5, y-5);
 path.transform(matrix);
 tempCanvas.drawPath(path, myPaint4); 
 }