如何暂停和恢复旋转动画android?

P A*_*sai 0 animation android imageview android-animation

我已经在音频播放器屏幕上实现了图像旋转动画,当音频开始而不是图像旋转时,当用户点击暂停按钮动画停止时,我使用 clearAnimation() 方法来停止动画,当用户恢复时我调用 startAnimation() 方法,但是这个看起来很糟糕,因为当我清除动画图像时,如 90 度不同,当我再次 startAnimation() 时,其起点为 0。请查看此视频,播放/暂停音频时动画出现问题观看此视频

所以我找到了一个 pause()/resume() 动画以获得更好的平滑度。谁能帮我解决动画平滑度或工作面糊?

Aka*_*dze 5

使用Animatorobject 为视图的属性设置动画(如android:rotation):

View imgView = findViewById(R.id.image);
View playPauseBtn = findViewById(R.id.button);

final ObjectAnimator anim = ObjectAnimator.ofFloat(imgView, View.ROTATION, 0f, 90f)
        .setDuration(4000);
anim.setRepeatCount(Animation.INFINITE);
anim.setInterpolator(new LinearInterpolator());
anim.start();

playPauseBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (anim.isPaused()) {
            anim.resume();
        } else {
            anim.pause();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)