Code example for ObjectAnimator

Methods: addListener, addUpdateListener, setInterpolator, start

1
        cancel(false); 
        animator = newInstance;
 
        // Invalidate 
        if (update == null) {
            animator.addUpdateListener(new AnimatorUpdateListener() {
                float oldValue = -1f;
 
                @Override 
                public void onAnimationUpdate(ValueAnimator animation) {
                    final float value = animation.getAnimatedFraction();
                    if (value != oldValue) rootView.postInvalidate();
                    oldValue = value;
                }}); 
        } else { 
            animator.addUpdateListener(update);
        } 
         
        animator.setInterpolator(interpolator);
 
        if (executeAfter != null) {
            animator.addListener(new Animator.AnimatorListener() {
                boolean canceled = false;
                @Override public void onAnimationRepeat(Animator animation) {}
                @Override public void onAnimationStart(Animator animation) {}
                @Override public void onAnimationCancel(Animator animation) {
                    canceled = true; 
                } 
                @Override public void onAnimationEnd(Animator animation) {
                    if (!canceled) executeAfter.run(); 
                }}); 
        } 
         
        animator.start(); 
    } 
 
    public void cancel(boolean unschedule) {
        if (unschedule) handler.removeCallbacksAndMessages(null);
        if (animator != null) animator.cancel();