title: i have one problem with animation drag and drop
body: <p>I am implementing the way to move a view across the screen but I need to know how to validate that it does not leave the edges of the screen.</p>
  
  <p><a href="https://i.stack.imgur.com/ReMMl.png" rel="nofollow noreferrer">image</a></p>
  
  <p><a href="https://i.stack.imgur.com/SB9D4.png" rel="nofollow noreferrer">image 2</a></p>
  
  <p>i don`t want happen this</p>
  
  <p><a href="https://i.stack.imgur.com/NlUNa.png" rel="nofollow noreferrer">image 3</a></p>
  
  <p>code of mi activity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  
  private ImageView img;
  private RelativeLayout relativeLayout;
  private View rootLayout;
  private int _xDelta;
  private int _yDelta;
  private TextView textView;
  
  private int modificarX = 350;
  private int modificarY = 350;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      textView = findViewById(R.id.get);
      rootLayout = (View) findViewById(R.id.view_root);
      img = (ImageView) rootLayout.findViewById(R.id.imageView);
  
      final RelativeLayout.LayoutParams[] layoutParams = {new RelativeLayout.LayoutParams(600, 600)};
      img.setLayoutParams(layoutParams[0]);
      img.setOnTouchListener(new ChoiceTouchListener());
  
  }
  
  private final class ChoiceTouchListener implements View.OnTouchListener {
      public boolean onTouch(View view, MotionEvent event) {
  
          final int X = (int) event.getRawX();
          final int Y = (int) event.getRawY();
          textView.setText("X: " + X + " Y: " + Y);
          switch (event.getAction() &amp; MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                  RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
                  _xDelta = X - lParams.leftMargin;
                  _yDelta = Y - lParams.topMargin;
  
                  break;
              case MotionEvent.ACTION_UP:
                  break;
              case MotionEvent.ACTION_POINTER_DOWN:
                  break;
              case MotionEvent.ACTION_POINTER_UP:
                  break;
              case MotionEvent.ACTION_MOVE:
                  RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
                          .getLayoutParams();
  
                      layoutParams.leftMargin = X - _xDelta - 10;
                      layoutParams.topMargin = Y - _yDelta;
                      layoutParams.rightMargin = -250;
                      layoutParams.bottomMargin = -250;
                      view.setLayoutParams(layoutParams);
                      Toast.makeText(MainActivity.this, "X: " + X + " Y: " + Y, Toast.LENGTH_LONG).show();
                      rootLayout.getRight();
                  break;
          }
          rootLayout.invalidate();
          return true;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>someone help me please with this, i need this, thank you</p>