title: Android how to drag imageview in relativelayout and then bring it back to place
body: <p>I'm trying to make an imageview draggable using onTouchListener. This is the code i have so far for the drag</p>
  
  <pre><code>switch (ME.getAction()){
      case MotionEvent.ACTION_DOWN://IF USER PRESSED ON THE IMAGE
  
          origix = v.getLeft();   //save original x coordinate calculated with the offset
          origiy = v.getTop();
  break;
  case MotionEvent.ACTION_MOVE://IF USER IS MOVING THE IMAGE
  
  
              System.out.println("MOVED");
              int x_cord = (int)ME.getRawX(); //get coordinate of the user touch
              int y_cord = (int)ME.getRawY(); 
  
              //set the image to the new coordinates based on where the user is touching and dragging
              MarginLayoutParams marginParams = new MarginLayoutParams(v.getLayoutParams());   
              marginParams.setMargins(x_cord - origix, y_cord - origiy,0, 0);
              RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
              v.setLayoutParams(layoutParams);  
              MOVED = true;   //mark that the image has been move
  
      break;
  </code></pre>
  
  <p>The variable 'v' is the imageview. The issue im getting is that the getRawX and getRawY isnt returning the correct coordinates (i think...). When i try touch the image and then try to drag it, the image starts dragging from another position. Usually much higher and little more to the right than the original position. The imageview is in a RelativeLayout and i'm using API 10</p>