Code example for ValueAnimator

Methods: cancel, getAnimatedValue, getCurrentPlayTime, setDuration, setFloatValues, start

0
            } 
        }); 
    } 
 
    private void animate(int direction) {
        final long currentPlayTime = mAnimator.getCurrentPlayTime();
        final float toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue;
        final float startValue = mFirstRun ? mOriginalFromValue :
                (Float) mAnimator.getAnimatedValue();
 
        // Make sure it's stopped before we modify any values 
        cancel(); 
 
        // TODO: We don't really need to do the animation if startValue == toValue, but 
        // somehow that doesn't seem to work, possibly a quirk of the animation framework 
        mDirection = direction;
 
        // Ensure we don't calculate a non-sensical duration 
        long duration = mOriginalDuration - currentPlayTime;
        mAnimator.setDuration(Math.max(0, Math.min(duration, mOriginalDuration)));
 
        mAnimator.setFloatValues(startValue, toValue);
        mAnimator.start();
        mFirstRun = false;
    } 
 
    public void cancel() { 
        mAnimator.cancel();
        mDirection = STOPPED;
    } 
 
    public void end() { 
        mAnimator.end();