create Animator Set from Animators - Android android.animation

Android examples for android.animation:Animator

Description

create Animator Set from Animators

Demo Code


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

import java.util.HashSet;

public class Main {
    private static HashSet<Animator> sAnimators = new HashSet<Animator>();
    static Animator.AnimatorListener sEndAnimListener = new Animator.AnimatorListener() {
        public void onAnimationStart(Animator animation) {
        }/*from www .  j  a v a 2 s  .co  m*/

        public void onAnimationRepeat(Animator animation) {
        }

        public void onAnimationEnd(Animator animation) {
            sAnimators.remove(animation);
        }

        public void onAnimationCancel(Animator animation) {
            sAnimators.remove(animation);
        }
    };

    public static AnimatorSet createAnimatorSet() {
        AnimatorSet anim = new AnimatorSet();
        cancelOnDestroyActivity(anim);
        return anim;
    }

    public static void cancelOnDestroyActivity(Animator a) {
        sAnimators.add(a);
        a.addListener(sEndAnimListener);
    }
}

Related Tutorials