I realize that the pause and resume methods on objectanimator objects are only available for API:19. However, since neither I, nor half of the android users out there have this API, is there an alternative to get your animation to pause and then resume from the same state instead of starting back from the beginning? Any help would be greatly appreciated.
In my project I had to make rotate animation (that will be pause and than resume from the same/end position), and I solved it by getting the current time of the animator (when animation ends/when I click pause) and than, after starting the animator I'm setting the "setCurrentPlayTime(with the ending time)". For getting the current time I'm using getCurrentPlayTime(); and for setting the time I'm using setCurrentPlayTime() of the ObjectAnimator class.
References: http://developer.android.com/reference/android/animation/ValueAnimator.html#setCurrentPlayTime(long) http://developer.android.com/reference/android/animation/ValueAnimator.html#getCurrentPlayTime()
private ObjectAnimator mObjectAnimator;
private long mAnimationTime;
private void stopAnimation() {
if(mObjectAnimator != null) {
mAnimationTime = mObjectAnimator.getCurrentPlayTime();
mObjectAnimator.cancel();
}
}
private void playAnimation() {
if (mObjectAnimator != null) {
mObjectAnimator.start();
mObjectAnimator.setCurrentPlayTime(mAnimationTime);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With