Code example for ValueAnimator

Methods: getAnimatedFraction

0
    public void runValueAnimator(final View view) {
        ValueAnimator anim = ValueAnimator.ofFloat(0, 400);
        anim.addUpdateListener(new AnimatorUpdateListener() {
            @Override 
            public void onAnimationUpdate(ValueAnimator animator) {
                float fraction = animator.getAnimatedFraction();
                view.setTranslationX(TX_START + fraction * (TX_END - TX_START));
                view.setTranslationY(TY_START + fraction * (TY_END - TY_START));
            } 
        }); 
        anim.start();
    } 
 
    /** 
     * ViewPropertyAnimator is the cleanest and most efficient way of animating 
     * View properties, even when there are multiple properties to be animated 
     * in parallel. 
     */ 
    public void runViewPropertyAnimator(View view) {
        view.animate().translationX(TX_END).translationY(TY_END);
    }