title: Move a view by translate animation Android
body: <p>I am trying to move a view on the screen to a random point by clicking it, then have it stay there and move again by click, however, the view only does the correct movement when starting at 0,0 coordinates, once changed, it is animating from random position to random position and finishing on a third random position.</p>
  
  <p>here is my snippet, can some one please run this and see if it works properly? and if not, what am i missing?</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  ImageView image;
  Rect rect;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      DisplayMetrics displaymetrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
      final int height = displaymetrics.heightPixels;
      final int width = displaymetrics.widthPixels;
  
      image = (ImageView) findViewById(R.id.image);
  
      findViewById(R.id.image).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final int newLeft = ((int)Math.round(Math.random()*width))/2;
              final int newTop = ((int)Math.round(Math.random()*height))/2;;
              final int newRight = ((int)Math.round(Math.random()*width))/2;;
              final int newBottom = ((int)Math.round(Math.random()*height))/2;;
              rect = new Rect(newLeft, newTop, newRight, newBottom);
  
             doSomeAnimation(rect);
  
          }
      });
  }
  
   public void doSomeAnimation(final Rect rect) {
      final FrameLayout.LayoutParams imageParasms = (FrameLayout.LayoutParams) image.getLayoutParams();
  
  
      TranslateAnimation animation = new TranslateAnimation(
              imageParasms.leftMargin, rect.left, imageParasms.topMargin, rect.top);
  
  
  
      animation.setDuration(1000);
  
      animation.setAnimationListener(new Animation.AnimationListener() {
          @Override
          public void onAnimationStart(Animation animation) {
  
         }
  
          @Override
          public void onAnimationEnd(Animation animation) {
  
  
              FrameLayout.LayoutParams imageParasms = (FrameLayout.LayoutParams) image.getLayoutParams();
              imageParasms.width = rect.width();
              imageParasms.height = rect.height();
  
              imageParasms.leftMargin = rect.left;
              imageParasms.topMargin = rect.top;
  
              image.setLayoutParams(imageParasms);
  
              image.requestLayout();
  
               }
  
          @Override
          public void onAnimationRepeat(Animation animation) {
  
          }
      });
  
      image.startAnimation(animation);
  }
  </code></pre>