title: Rotate an Imagewith Animation
body: <p><img src="https://i.stack.imgur.com/IS7ZH.png" alt="The two states of the image"></p>
  
  <p><strong>What I Have</strong></p>
  
  <p>I have an arrow image (like the left one). When the user clicks on it, it should rotate 180 degree with an animation and should look like the right one.</p>
  
  <p><strong>What I Have Done</strong></p>
  
  <pre><code>private void rotate(float degree, final int toggleV) {
  
          final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
                  RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                  RotateAnimation.RELATIVE_TO_SELF, 0.5f);
  
          rotateAnim.setDuration(500);
          toggle.startAnimation(rotateAnim);
          rotateAnim.setAnimationListener(new Animation.AnimationListener() {
  
              @Override
              public void onAnimationStart(Animation animation) {
  
              }
  
              @Override
              public void onAnimationEnd(Animation animation) {
  
  
                  if (toggleV == 1)
                      toggle.setImageResource(R.drawable.toggle_up);
                  else
                      toggle.setImageResource(R.drawable.toggle_down);
              }
  
              @Override
              public void onAnimationRepeat(Animation animation) {
  
              }
          });
      }
  </code></pre>
  
  <p><strong>The Problem</strong></p>
  
  <p>I see that the animation works fine but there is a little flicker while setting the image. May be because of the time difference when the animation ends and the image is set.</p>
  
  <p>How can I remove this flicker issue? Do you have any better approach to do this?</p>