如何恢复和暂停ObjectAnimator在Android中为API水平低于19? [英] How to resume and pause ObjectAnimator in Android for API Levels below 19?

查看:4560
本文介绍了如何恢复和暂停ObjectAnimator在Android中为API水平低于19?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,API级别19支暂停()和resume()上ObjectAnimators。但是,在我的项目在API级别14,我有被应用到图像,以旋转的ObjectAnimator。我想暂停触摸所提供的ObjectAnimator动画,并从地方恢复它在图像的观点是(触摸先下去)。

I am aware that API level 19 supports pause() and resume() on ObjectAnimators. But in my project at API level 14, I have an ObjectAnimator which is applied to an Image view to rotate it. I want to pause the animation provided by the ObjectAnimator on touch and resume it from the place where the image view was (before touch down).

所以我试图保存当前的播放时间并取消该对象的动画在我的stopAnimation()函数。

So I attempted to save the current play time and cancel the object animator on my stopAnimation() function.

private void stopAnimation(){
        currentTime = mGlobeAnimator.getCurrentPlayTime();
        mGlobeAnimator.cancel();
    }

在startAnimation()函数,我重新创建动画,设置它的目标图像视图,设置保存的播放时间,并启动它。

In the startAnimation() function, I recreate the animator, set its target to the image view, set the saved play time and start it.

private void startAnimation(Context context, View view, float startAngle) {
        ObjectAnimator globeAnimatorClone = (ObjectAnimator)AnimatorInflater.loadAnimator(context, R.animator.rotate_globe);
        globeAnimatorClone.setTarget(mImageView);
        globeAnimatorClone.setCurrentPlayTime(currentTime);
        globeAnimatorClone.start();
}

这是行不通的。会有人帮助,请与任何指针暂停和19日以前恢复对API级别提供的动画动画?

This does not work. Would anybody help please with any pointers to pause and resume animation provided by animator for API level before 19?

推荐答案

我想我懂了工作通过启动动画,然后设置currentPlayTime()。该文件清楚地告诉(我只是偶然),如果动画尚未启动,currentPlayTime设置使用这种方法不会前进前进!

I think I got it working by starting the animator and then setting the currentPlayTime(). The documentation clearly tells (which I just stumbled upon) that if the animation has not been started, the currentPlayTime set using this method will not advance the forward!

设定动画在指定时间点的位置。这个时候应该是介于0和动画的总持续时间,包括任何重复。如果动画尚未开始,那么就不会前进向前后它被设置为这个时间;它只需设置时间这个数值,并依据该时间的任何适当的行动。如果动画已​​经在运行,那么setCurrentPlayTime()将当前播放时间设定为这个值,并继续从该点播放。 <一href="http://developer.android.com/reference/android/animation/ValueAnimator.html#setCurrentPlayTime(long)" rel="nofollow">http://developer.android.com/reference/android/animation/ValueAnimator.html#setCurrentPlayTime(long)

Sets the position of the animation to the specified point in time. This time should be between 0 and the total duration of the animation, including any repetition. If the animation has not yet been started, then it will not advance forward after it is set to this time; it will simply set the time to this value and perform any appropriate actions based on that time. If the animation is already running, then setCurrentPlayTime() will set the current playing time to this value and continue playing from that point. http://developer.android.com/reference/android/animation/ValueAnimator.html#setCurrentPlayTime(long)

private void stopAnimation(){
    mCurrentPlayTime = mRotateAntiClockwiseAnimator.getCurrentPlayTime();
    mRotateAntiClockwiseAnimator.cancel();
}

private void startAnimation() {
        mRotateAntiClockwiseAnimator.start();
        mRotateAntiClockwiseAnimator.setCurrentPlayTime(mCurrentPlayTime);
}

这篇关于如何恢复和暂停ObjectAnimator在Android中为API水平低于19?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆