Update: 20/11/13: This is still unresolved.
I am trying to animate the creation of a circle in a custom view. I would like to animate the creation of the circumference - at the beginning of the animation there is an arc, and by the end of the animation, the circle is complete.
I did this sucessfully by following this answer - https://stackoverflow.com/a/11168363/2442638 - and just adding a repeating Handler
to increase the sweepAngle
and call invalidate();
However, this doesn't work the way I would like it to as I cannot set the duration to complete the circle.
This is my current code:
Path mOuterCirclePath = new Path();
final RectF mOval = new RectF();
int mSweepAngle = 0;
int mStartAngle = -90;
@Override
protected void onDraw(Canvas canvas) {
mOval.set(0, 0, mBorderRect.right, mBorderRect.bottom); //mBorderRect is the outside border of my view
mOuterCirclePath.arcTo(mOval, 0, 0, true);
canvas.drawArc(mOval, -mStartAngle, mSweepAngle, false,
mOuterCirclePaint);
}
public void drawOuterCircle() {
startUpdateOuterCircle();
}
Runnable mCircleInvalidator = new Runnable() {
@Override
public void run() {
if (mSweepAngle <= 360) {
mSweepAngle++
}
invalidate();
mHandler.postDelayed(mCircleInvalidator, 20);
}
};
void startUpdateOuterCircle() {
mCircleInvalidator.run();
}
void stopUpdateOuterCircle() {
mHandler.removeCallbacks(mCircleInvalidator);
}
The main question is: How do I set the duration for the animation? I would like this to be easily changeable, like it is in the animator classes.
P.S. As far as I'm aware I can't use any of the animators such as ViewPropertyAnimator
of 'ObjectAnimator' for this. Please correct me if I'm wrong!