Code example for TranslateAnimation

Methods: setAnimationListener, setDuration, setRepeatCount, setRepeatMode, setStartOffset

0
        final AlphaAnimation fadeOutAnimation = new AlphaAnimation(1, 0);
        fadeOutAnimation.setDuration(500);
        fadeOutAnimation.setFillAfter(true);
 
        float y_delta = -button.getTop() + calculateScaledDelta(20);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0,
                                                                       y_delta);
        translateAnimation.setStartOffset(500);
        translateAnimation.setDuration(1500);
        translateAnimation.setRepeatMode(Animation.REVERSE);
        translateAnimation.setRepeatCount(1);
 
        animationSet = new AnimationSet(true);
 
        Animation.AnimationListener translateListener = new Animation.AnimationListener() {
            @Override 
            public void onAnimationStart (Animation animation) {}
 
            @Override 
            public void onAnimationEnd (Animation animation) {
                pointer.setAnimation(fadeOutAnimation);
                fadeOutAnimation.start();
            } 
 
            @Override 
            public void onAnimationRepeat (Animation animation) {
 
                button.setPressed(true);
                handler.postDelayed(new Runnable() {
                    @Override 
                    public void run() { 
                        button.setPressed(false);
                        button.setChecked(false);
                    } 
                }, 100); 
            } 
        }; 
 
        Animation.AnimationListener fadeOutListener = new Animation.AnimationListener() {
            @Override 
            public void onAnimationStart (Animation animation) {}
 
            @Override 
            public void onAnimationEnd (Animation animation) {
                touchShield.setVisibility(View.GONE);
            } 
 
            @Override 
            public void onAnimationRepeat (Animation animation) {}
        }; 
        translateAnimation.setAnimationListener(translateListener);
        fadeOutAnimation.setAnimationListener(fadeOutListener);
        animationSet.addAnimation(scaleAnimationPressUp);
        animationSet.addAnimation(scaleAnimationPressDown);
        animationSet.addAnimation(fadeInAnimation);
        animationSet.addAnimation(translateAnimation);