title: How to have an image as a background in a FrameLayout and an image inside to let the user drag within the layout
body: <p>I am looking have a layout with an image as background and add an image inside which allows me to drag within the layout only. How can I achieve it?</p>
  
  <p>So let's say the red area is my framelayout and the orange box is the image:
  <img src="https://i.stack.imgur.com/JQMFa.jpg" alt="enter image description here"></p>
  
  <p>The app loads with the orange all the to the bottom and left and then I want to let the user drag it around the red area only.</p>
  
  <pre><code>If (orange.x goes beyond left of the red box) {
       the orange box.x = the orange box + the orange box.width;
  }
  else if (orange.x goes beyond the right of the red box) {
       the orange box.x = the orange box - the orange box.width;
  }
  
  else If (orange.y goes beyond top of the red box) {
       the orange box.y = the orange box + the orange box.width;
  }
  else if (orange.y goes beyond the bottom of the red box) {
       the orange box.y = the orange box - the orange box.width;
  }
  else { // do not allow use to drag outside, if they do drag it outside leave the orange box the last known position inside the red box area
       y = orange box.y; //get x coordinate of the orange box
       x = orange box.x; //get y coordinate of the orange box
  }
  </code></pre>
  
  <p>So I can setup my XML like this:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/redboxarea"&gt;
  
  &lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;ImageView  
      android:layout_width="@dimen/widthsmall" 
      android:layout_height="@dimen/heightsmall" 
      android:scaleType="fitXY"
      android:src="@drawable/orangebox"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>How can I achieve the android code to achieve what I am looking to do? Or is something else recommended?</p>