views:

59

answers:

1

Hi

I'm doing animation of spinning with different images (like horizontal roulette) one image at a time from left to right over the screen.

At every animation cycle I need to change image to random from the list, so I found if I use repeating animation then setting new ImageResource on onAnimationRepeat of AnimationListener doesn't update my ImageView. I've decided to use custom triggering of next animation from onAnimationEnd. Here a pice of code:

    ImageView image = (ImageView)(ImageView)findViewById(R.id.imageId);

    Animation aMid = AnimationUtils.loadAnimation(this, R.anim.plant_middle);  
    aMid.setFillEnabled(true);
    aMid.setFillAfter(true);
    aMid.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) { 
            setRandomImageResource();
        }

        @Override
        public void onAnimationRepeat(Animation animation) { }

        @Override
        public void onAnimationEnd(Animation animation) {
            if(customCounter < SPIN_COUNT){
                customCounter++;
                image.startAnimation(aMid);
            }
        }
   });

And Animation ixm is pretty simple, it's about ImageView comes from left of the screen to it's right:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="true">

    <translate
         android:interpolator="@android:anim/linear_interpolator"
         android:fromXDelta="-100%"
         android:toXDelta="100%"
         android:fromYDelta="0%"
         android:toYDelta="0%"
         android:duration="4000" /> 
</set>

The problem is in that between every animation cycle ImageView appears in the center of the screen for a very short moment, like it is flying from right back to left to start next animation cycle, or like it flickers in the middle where it's initially positioned in layout xml.

Setting it's visibility to GONE on onAnimationEnd and VISIBLE on onAnimationEnd doesn't work our the problem.

What do?

A: 

I managed to achieve needed by setting layout margin left to -1000 and back on onAnimationEnd/onAnimationStart instead of doing visibility. However solution is ugly.

dykzei eleeot