Create a pair of Flip Animation that can be used to flip 3D transition from fromView to toView . - Android User Interface

Android examples for User Interface:View Animation

Description

Create a pair of Flip Animation that can be used to flip 3D transition from fromView to toView .

Demo Code


import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.Interpolator;
import android.widget.ViewAnimator;

public class Main{
    /**/*from   w w w.  j a v  a 2s.com*/
     * Create a pair of {@link FlipAnimation} that can be used to flip 3D
     * transition from {@code fromView} to {@code toView}. A typical use case is
     * with {@link ViewAnimator} as an out and in transition.
     * 
     * NOTE: Avoid using this method. Instead, use {@link #flipTransition}.
     * 
     * @param fromView
     *            the view transition away from
     * @param toView
     *            the view transition to
     * @param dir
     *            the flip direction
     * @param duration
     *            the transition duration in milliseconds
     * @param interpolator
     *            the interpolator to use (pass {@code null} to use the
     *            {@link AccelerateInterpolator} interpolator)
     * @param depthZ
     *            depth of the view when the animation starts
     * @return array of animation
     */
    public static Animation[] flipAnimation(final View fromView,
            final View toView, FlipDirection dir, long duration,
            Interpolator interpolator, float depthZ) {
        Animation[] result = new Animation[2];
        float centerX;
        float centerY;

        centerX = fromView.getWidth() / 2.0f;
        centerY = fromView.getHeight() / 2.0f;

        Animation outFlip = new Rotate3dAnimation(
                dir.getStartDegreeForFirstView(),
                dir.getEndDegreeForFirstView(), centerX, centerY, depthZ,
                false);
        outFlip.setDuration(duration);
        outFlip.setFillAfter(true);
        outFlip.setInterpolator(interpolator == null ? new AccelerateInterpolator()
                : interpolator);

        AnimationSet outAnimation = new AnimationSet(true);
        outAnimation.addAnimation(outFlip);
        result[0] = outAnimation;

        Animation inFlip = new Rotate3dAnimation(
                dir.getStartDegreeForSecondView(),
                dir.getEndDegreeForSecondView(), centerX, centerY, depthZ,
                false);
        inFlip.setDuration(duration);
        inFlip.setFillAfter(true);
        inFlip.setInterpolator(interpolator == null ? new AccelerateInterpolator()
                : interpolator);
        inFlip.setStartOffset(duration);

        AnimationSet inAnimation = new AnimationSet(true);
        inAnimation.addAnimation(inFlip);
        result[1] = inAnimation;

        return result;
    }
}

Related Tutorials