title: How to stop animation at end of cycle?
body: <p>I have an ImageView that I'm rotating for use as a loading animation. Once my data is loaded, I try to stop the animation, but instead of cycling to the end and then stopping, the animation goes to a halfway point, then stops, and then the image snaps back to its original state, which looks pretty ugly.</p>
  
  <p>Here is what I've tried:</p>
  
  <p>Option 1:</p>
  
  <pre><code>ImageView iv = (ImageView) findViewById(R.id.refreshImage);
  if (iv != null) {
      iv.clearAnimation();
  }
  </code></pre>
  
  <p>Option 2:</p>
  
  <pre><code>ImageView iv = (ImageView) findViewById(R.id.refreshImage);
  if (iv != null &amp;&amp; iv.getAnimation() != null) {
      iv.getAnimation().cancel();
  }
  </code></pre>
  
  <p>Option 3:</p>
  
  <pre><code>ImageView iv = (ImageView) findViewById(R.id.refreshImage);
  if (iv != null &amp;&amp; iv.getAnimation() != null) {
      iv.getAnimation().setAnimationListener(new AnimationListener() {
  
          @Override
          public void onAnimationStart(Animation animation) {
  
          }
  
          @Override
          public void onAnimationRepeat(Animation animation) {
              animation.cancel();
  
          }
  
          @Override
          public void onAnimationEnd(Animation animation) {
  
          }
      });
  }
  </code></pre>
  
  <p>The end result is the same in all three cases. How do I rotate the image and have it end up back where it started? </p>
  
  <p>Edit:</p>
  
  <p>Some further information: My rotation animation:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;rotate xmlns:android="http://schemas.android.com/apk/res/android"
  android:duration="1000"
  android:fromDegrees="0"
  android:interpolator="@android:anim/linear_interpolator"
  android:pivotX="50%"
  android:pivotY="50%"
  android:toDegrees="360" /&gt;
  </code></pre>
  
  <p>How I start the animation:</p>
  
  <pre><code>ImageView iv = (ImageView) findViewById(R.id.refreshImage);
  Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
  rotation.setRepeatCount(Animation.INFINITE);
  iv.startAnimation(rotation);
  </code></pre>