Stop rotate View animation - Android android.view.animation

Android examples for android.view.animation:Rotate Animation

Description

Stop rotate View animation

Demo Code

import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.LinearInterpolator;

public class Main {
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  public static void rotateViewStop(final View view) {
    float startDegree = view.getRotation();
    if (startDegree == 0.0F) {
      return;//from  ww w . j  a va 2s. co  m
    }
    long time = (long) (360.0F - startDegree) * 2L;
    ViewPropertyAnimator viewPropertyAnimator = view.animate();
    viewPropertyAnimator.setInterpolator(new LinearInterpolator());
    viewPropertyAnimator.rotation(360.0f);
    viewPropertyAnimator.setDuration(time);
    viewPropertyAnimator.withEndAction(new Runnable() {
      @Override
      public void run() {
        view.setRotation(0.0f);
      }
    });
    viewPropertyAnimator.start();
  }
}

Related Tutorials