0

I have a spinning wheel, which is an ImageView, in my app, and the animation is working well, but the issue is for just a split second it snaps back to it's original position (0 degree rotation). The .gif below shows what I am talking about.

enter image description here

The last split second of the rotation it has that awkward snap back that makes the animation look extremely unsmooth.

I am looking for a way to fix this but I cannot quite figure it out. This is my code right now that animates the ImageView and rotates it to the final position of the animation

ImageView readyButton = findViewById(R.id.spinnerready);
final ImageView spinnerSpin = findViewById(R.id.spinnerspin);
final Animation animRotate = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animRotate.setDuration(5000);
animRotate.setRepeatCount(0);

    readyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            float newDeg = ROTATE_TO;
            spinnerSpin.startAnimation(animRotate);

            spinnerSpin.postDelayed(new Runnable() {
                @Override
                public void run() {
                    spinnerSpin.setRotation(ROTATE_TO);
                }
            }, 5000);

            while(newDeg > 360) {
                newDeg = newDeg - 360;
            }
        }
    });

I have also tried changing the delay of the rotation to 4500 instead of 5000 but the issue is not fixed. Is there a way to eliminate the ImageView from going back to its original position after the animation?

brent_mb
  • 337
  • 1
  • 2
  • 14
  • Wouldn't you say your `spinnerSpin.setRotation(ROTATE_TO)` call is causing the glitch? You can just use an `AnimationListener` to determine when the spin has completed. – greeble31 Jan 27 '19 at 15:55
  • @greeble31 thanks for the reply! So I have tried using `AnimationListener` before I went to the method I posted about, and the same issue occurred. In my `onAnimationEnd` method I use the `spinnerSpin.setRotation(ROTATE_TO);` line so that the spinner is rotated to the position that the animation rotates to. Otherwise it will snap back to it's original position before the animation started. Do you know of anything I can put in the `onAnimationEnd` method that will prevent the `ImageView` from rotating back to its original position after the animation is over? – brent_mb Jan 27 '19 at 16:10
  • 1
    My bad, correct answer is to use `animRotate.setFillAfter( true )` – greeble31 Jan 27 '19 at 16:22
  • Possible duplicate of [Android: Animation Position Resets After Complete](https://stackoverflow.com/questions/3882826/android-animation-position-resets-after-complete) – greeble31 Jan 27 '19 at 16:22

0 Answers0