title: TranslateAnimation on ImageView (Android)
body: <p>So I have an ImageView in my layout and I wanted to slide it to the right or left when the user swipe over the latter. I used TranslateAnimation to translate the ImageView, as shown below.</p>
  
  <pre><code>ImageView logoFocus = (ImageView) findViewById(R.id.logoFocus);
  
  Animation animSurprise2Movement = new TranslateAnimation(logoFocus.getLeft(), logoFocus.getLeft()+150, logoFocus.getTop(), logoFocus.getTop());
  animSurprise2Movement.setDuration(1000);
  animSurprise2Movement.setFillAfter(true);
  animSurprise2Movement.setFillEnabled(true);
  logoFocus.startAnimation(animSurprise2Movement);
  </code></pre>
  
  <p>I've placed this code in my Swipe Right section, and the same code but using getLeft()-150 for the Swipe Left section. It works as expected when I swipe a first time, but when I swipe to the other direction, the ImageView goes back to its original position, then slides in the other direction, instead of only sliding to the original position.</p>
  
  <p>I've already tried to add the following in the onAnimationEnd method of an AnimationListener which I've set to the Animation, but in vain.</p>
  
  <pre><code>MarginLayoutParams params = (MarginLayoutParams) logoFocus.getLayoutParams();
  params.setMargins(logoFocus.getLeft()+150, logoFocus.getTop(), logoFocus.getRight(), logoFocus.getBottom());
  logoFocus.setLayoutParams(params);
  </code></pre>
  
  <p>I've also tried the following in the same method, but that neither didn't work as expected.</p>
  
  <pre><code>((RelativeLayout.LayoutParams) logoFocus.getLayoutParams()).leftMargin += 150;
  logoFocus.requestLayout();
  </code></pre>
  
  <p>Would anyone please help me? The position doesn't seem to change after the Animation, even with setFillAfter(true) and setFillEnabled(true) used. Is there an alternative to using TranslateAnimation?</p>
  
  <p>Thank you for any help I can get. :)</p>