P A Gosai
P A Gosai

Reputation: 591

How to pause and resume rotate animation android?

I have implemented image rotate animation on the audio player screen where when audio start than image rotation and when a user clicks on pause button animation stop, I use clearAnimation() method for stopping animation and when user resume I call startAnimation() method but this Look bad because when I clear animation image degree like 90 was different and when I startAnimation() again its starting point was 0. please check this video where animation having an issue while play/pause audio Watch This Video.

So I find a pause()/resume() animation for better smoothness. Can anyone help me to sort out animation smoothness or working batter?

Upvotes: 1

Views: 2013

Answers (1)

Akaki Kapanadze
Akaki Kapanadze

Reputation: 2672

Use Animator object to animate the view's property (like 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();
        }
    }
});

Upvotes: 7

Related Questions