Create ObjectAnimator from Property Values Holder - Android android.animation

Android examples for android.animation:ObjectAnimator

Description

Create ObjectAnimator from Property Values Holder

Demo Code


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

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;

import java.util.HashSet;

public class Main {
    static HashSet<Animator> sAnimators = new HashSet<Animator>();
    static Animator.AnimatorListener sEndAnimListener = new Animator.AnimatorListener() {
        public void onAnimationStart(Animator animation) {
        }/*ww w. j  ava 2s.  c o m*/

        public void onAnimationRepeat(Animator animation) {
        }

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

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

    public static ObjectAnimator ofPropertyValuesHolder(Object target,
            PropertyValuesHolder... values) {
        ObjectAnimator anim = new ObjectAnimator();
        anim.setTarget(target);
        anim.setValues(values);
        cancelOnDestroyActivity(anim);
        return anim;
    }

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

Related Tutorials