Code example for ValueAnimator

Methods: cancelgetAnimatedValuegetCurrentPlayTimesetFloatValuesstart

    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()).floatValue();
        // Make sure it's stopped before we modify any values 
        // 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);
        mFirstRun = false;
    public void cancel() { 
        mDirection = STOPPED;
    public void end() { 
Stop searching for code, let great code find you!  Add Codota to your java IDE