title: ImageView drag&drop
body: <p>I have image what is bigger than actual screen. I have code to drag&amp;drop... everything is working, but the problem when i drag the image, it can go out of screen/view. I would like to make it to corners not go outside... stop when image corners/sides = screen sides... Can somebody help? I would like to make map to my game... If you test the code, you will see what is the problem exactly
  Base: i.imgur.com/G4BtCmS.jpg The problem: i.imgur.com/xi9x2nE.jpg And i want to drag stop when image drag = screen corners...all position...left, top, etc...: i.imgur.com/k6I7A7d.jpg But i this code, i can drag out of the screen....: i.imgur.com/xi9x2nE.jpg Can somebody help? How can i make drag&amp;drop boundary? Thank you 
  Thank you</p>
  
  <p>Here is the code:</p>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"&gt;
  
  &lt;ImageView
      android:id="@+id/image"
      android:layout_width="4000dp"
      android:layout_height="2000dp"
      android:background="@drawable/bgtest"
      android:layout_marginBottom="-1000dp"
      android:layout_marginStart="-2000dp"
      android:layout_marginTop="-500dp"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.backgroundtest;
  
  import android.annotation.SuppressLint;
  import android.graphics.PointF;
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.ImageView;
  
  
  import androidx.appcompat.app.AppCompatActivity;
  
  
  
  public class MainActivity extends AppCompatActivity {
  
  ImageView image;
  PointF DownPT = new PointF();
  PointF StartPT = new PointF();
  
  @SuppressLint("ClickableViewAccessibility")
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      image = (ImageView)findViewById(R.id.image);
  
      image.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              int eid = event.getAction();
              switch (eid)
              {
                  case MotionEvent.ACTION_MOVE :
                      PointF mv = new PointF( event.getX() - DownPT.x, event.getY() - DownPT.y);
                      image.setX((int)StartPT.x+mv.x);
                      image.setY((int)StartPT.y+mv.y);
                      StartPT = new PointF( image.getX(), image.getY());
                      break;
                  case MotionEvent.ACTION_DOWN :
                      DownPT.x = event.getX();
                      DownPT.y = event.getY();
                      StartPT = new PointF( image.getX(), image.getY());
                      break;
                  case MotionEvent.ACTION_UP :
                      break;
                  default:
                      break;
              }
  
              return true;
          }
      });
  
  
  }
  </code></pre>
  
  <p>}</p>