Rotate a view. - Android User Interface

Android examples for User Interface:View Rotate

Description

Rotate a view.

Demo Code


//package com.java2s;
import android.view.View;

import android.view.ViewPropertyAnimator;

import android.view.animation.Interpolator;

public class Main {
    /**/*w ww  .j  a va  2 s  . c  o  m*/
     * Rotate view.
     * @param view View to rotate.
     * @param toDegrees Target degrees.
     * @param duration Animation duration in milliseconds.
     */
    public static void rotate(View view, float toDegrees, long duration) {
        rotate(view, toDegrees, duration, null);
    }

    /**
     * Rotate view.
     * @param view View to rotate.
     * @param toDegrees Target degrees.
     * @param duration Animation duration in milliseconds.
     * @param interpolator Interpolator.
     */
    public static void rotate(View view, float toDegrees, long duration,
            Interpolator interpolator) {
        if (view == null)
            return;
        if (duration > 0) {
            ViewPropertyAnimator animator = view.animate();
            animator.rotation(toDegrees);
            animator.setDuration(duration);
            if (interpolator != null)
                animator.setInterpolator(interpolator);
            animator.start();
        } else
            view.setRotation(toDegrees);
    }
}

Related Tutorials