How to implement smooth shape shifting animation in android ?
I'm rendering polygon shapes on camera preview using canvas.draw(path, paint)
in OnDraw()
method of my custom view.
The path is being rendered something like this:
for (int i = 0; i < pointList.size(); i++) {
Point currentPoint = adjustedPointList.get(i);
if (i == 0) {
//for the first point, we only have to move to that point
firstPoint = currentPoint;
mPath.moveTo(currentPoint.getX(), currentPoint.getY());
//Animation here
} else {
//otherwise we draw a line between last position and current point
mPath.lineTo(currentPoint.getX(), currentPoint.getY());
//Animation here
}
}
//we have to draw a last line between last and first point
if (firstPoint != null) {
mPath.lineTo(firstPoint.getX(), firstPoint.getY());
//Animation here
}
I tried the ObjectAnimator
class like here but had no effect. Since this is constantly called inside a thread, the shape changes from frame to frame. This is where I want to have a smooth animation like here which is in iOS. How can I do the same for my above illustrated rendering ?
I have also tried solutions for the following questions :
But nothing served my purpose of smooth shape shifting or even animating the drawing of path. currently the shape shift is very flickery.
Also, lot of the shape shifting animation references for android uses bitmaps or SVG which is again not useful for me.
How can I implement this in android ? or is there a different approach to this ? If so, I would like to know everything about it. Thanks!