rotate View Stop - Android User Interface

Android examples for User Interface:View Rotate

Description

rotate View Stop

Demo Code


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;

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 w w  w  .jav  a  2  s.  c o 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