如何恢复和暂停Android中的ObjectAnimator API级别低于19?

我知道API级别19支持ObjectAnimators上的pause()和resume().但是在API级别14的项目中,我有一个ObjectAnimator应用于 Image视图来旋转它.我想在触摸时暂停ObjectAnimator提供的动画,并从图像视图所在的位置(触摸前)恢复它.

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

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

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

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级别提供的动画吗?

解决方法

我想通过启动动画师然后设置currentPlayTime()来实现它.文档清楚地告诉我(我只是偶然发现)如果动画尚未启动,使用此方法设置的currentPlayTime将不会向前推进!

将动画的位置设置为指定的时间点.此时间应介于0和动画的总持续时间之间,包括任何重复.如果尚未启动动画,则在设置为此时它不会前进;它只会将时间设置为此值,并根据该时间执行任何适当的操作.如果动画已在运行,则setCurrentPlayTime()会将当前播放时间设置为此值并从该点继续播放. 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);
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...