Avoid Flickering in Android animation- Smooth Transition Animation


You will get some flickering When you create a TranslateAnimation in android rooted device or container with custom animation.

This source will explain how to avoid the flickering in android animation. Mostly the flickering happened when you set the layout params of container after motion finished.

The solution is create a small animation with 0 bound transition after the animation ends.

  1. Create animation

    
    TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 100);
      animation.setDuration(700);
      animation.setFillAfter(true);
      animation.setAnimationListener(new AnimationListener() {
      public void onAnimationEnd(Animation animation) {
         footer.clearAnimation();
      footer.layout(footer.getLeft(), (footer.getTop() + 100), footer.getRight(), footer.getBottom());
                    }
    public void onAnimationRepeat(Animation animation) {
                    }
    public void onAnimationStart(Animation animation) {
     }});
     footer.startAnimation(animation);
      }
    
    
  2. Add the following code in animationListener (onAnimationEnd) onAnimationEnd overridden method

    
    animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
    animation.setDuration(1);
    footer.startAnimation(animation);0.0f, 0.0f, 0.0f, 0.0f); animation.setDuration(1); 
    footer.startAnimation(animation);