Search code examples
androidanimationviewflipper

Android ViewFlipper auto animation / looping breaks at last child view


I have made a ViewFlipper to simulate a slideshow component looping the slides continuously. I configured it be:

mViewFlipper.setAnimateFirstView(true);
mViewFlipper.setAutoStart(true);

Everything works fine until the last slide (or child view). At this moment the first slide appears abruptly without sliding !!!

I checked the ViewFlipper and ViewAnimation source code and found the following:

   void showOnly(int childIndex, boolean animate) {
       final int count = getChildCount();
       for (int i = 0; i < count; i++) {
           final View child = getChildAt(i);
           if (i == childIndex) {
               if (animate && mInAnimation != null) {
                   child.startAnimation(mInAnimation);
               }
               child.setVisibility(View.VISIBLE);
               mFirstTime = false;
           } else {
               if (animate && mOutAnimation != null && child.getVisibility() == View.VISIBLE) {
                   child.startAnimation(mOutAnimation);
               } else if (child.getAnimation() == mInAnimation)
                   child.clearAnimation();
               child.setVisibility(View.GONE);
           }
       }
   }

As you can see this method always starts with the lowest index to animate-in.

For example if I have 5 slides:

when the slide #4 is visible and should be replaced by slide #0, the slide #0 is animated-in before slide #4 is animated-out, which makes the animation sudden and not smooth at all.

Does anybody have any workaround to this problem ?

Thanks


Solution

  • It seems problem solved with the latest Android update:

    Lollipop 5.1.1 Build# LMY48M