run Flip Horizon Animation - Android android.animation

Android examples for android.animation:Animation

Description

run Flip Horizon Animation

Demo Code


//package com.java2s;
import android.animation.Animator;

import android.animation.AnimatorSet;

import android.animation.ObjectAnimator;

import android.support.annotation.NonNull;

import android.view.View;

public class Main {
    public static void runFlipHorizonAnimation(@NonNull View view,
            long duration, final Runnable rWhenEnd) {
        view.setAlpha(0);//  www.j  a v a  2 s  . co  m
        AnimatorSet set = new AnimatorSet();
        ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(view,
                "rotationY", -180f, 0f);
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(view,
                "alpha", 0f, 1f);
        set.setDuration(duration);
        set.playTogether(objectAnimator1, objectAnimator2);
        if (rWhenEnd != null)
            set.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    rWhenEnd.run();
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
        set.start();
    }
}

Related Tutorials