title: Drag and Drop imagebutton Dissapears behind different view
body: <p>I am programming an android game which users can purchase buildings that are dynamically created once purchased. When they are created, the user can drag and drop them wherever they want to, just as long as it is on the ground. I have the sky and the ground as two different frame layouts, but the sky takes up the top 25% and the ground takes up the bottom 75%. When the user drags the buildings around, they act as they should until the user tries to drag it into the sky area. Instead of it just snapping back to where it was, like I would prefer, it just disappears behind the sky area. </p>
  
  <p>Here is the xml for the top and bottom:</p>
  
  <pre><code>&lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:background="@drawable/mars"
      android:id="@+id/gameBackground" &gt;
  
      &lt;FrameLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="0.75"
          android:orientation="horizontal"
          android:id="@+id/topHalf" &gt;
  
      &lt;/FrameLayout&gt;
  
      &lt;FrameLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="0.25"
          android:orientation="horizontal"
          android:id="@+id/bottomHalf" &gt;
  
          &lt;ImageButton 
              android:id="@+id/polarCapButton1"
              android:orientation="vertical"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|left"
              android:background="@drawable/polarcap" /&gt;
  
          &lt;ImageButton 
              android:id="@+id/polarCapButton2"
              android:orientation="vertical"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="top|right"
              android:background="@drawable/polarcap" /&gt;
  
      &lt;/FrameLayout&gt;  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is the code for the creation of the imagebutton:</p>
  
  <pre><code>frame = (FrameLayout) findViewById(R.id.bottomHalf);
  newColonyHut = new ImageButton(runGraphics.this);
  newColonyHut.setBackgroundResource(R.drawable.mainhut);     
  newColonyHut.setTag("NewColonyHut");
  newColonyHut.setOnTouchListener(new ColonyHutClick());
  findViewById(R.id.bottomHalf).setOnDragListener(new ColonyHutDrag());
  FrameLayout.LayoutParams  param = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
  frame.addView(newColonyHut, param);
  </code></pre>
  
  <p>Here is the ColonyHutClick class:</p>
  
  <pre><code>public class ColonyHutClick implements OnTouchListener 
  {
      @Override
      public boolean onTouch(View v, MotionEvent event) 
      {
          ClipData.Item item = new ClipData.Item((CharSequence)v.getTag());
  
          String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN }; 
          ClipData data = new ClipData(v.getTag().toString(), mimeTypes, item); 
          DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v); 
  
          v.startDrag(data, shadowBuilder, v, 0);
          v.setVisibility(View.INVISIBLE);
  
          return false;
      }//end onTouch function
  }//end ColonyHutClick class
  </code></pre>
  
  <p>Here is the ColonyHutDrag class:</p>
  
  <pre><code>public class ColonyHutDrag extends Activity implements OnDragListener
  {
  
      @Override
      public boolean onDrag(View v, DragEvent event) 
      {
          int x = 0, y = 0;
          switch(event.getAction())
          {
              case DragEvent.ACTION_DRAG_STARTED:
                  //drag has started
                  break;
  
              case DragEvent.ACTION_DRAG_ENTERED:
                  //being dragged
                  break;
  
              case DragEvent.ACTION_DRAG_EXITED:
                  //stop drag
                  break;
  
              case DragEvent.ACTION_DRAG_LOCATION:
                  //find drag location
                  break;
  
              case DragEvent.ACTION_DROP:
                  if (v == v.findViewById(R.id.bottomHalf))
                  {
                      //find position where dropped
                      x = (int) event.getX();
                      y = (int) event.getY();
  
  
                      View view = (View) event.getLocalState();
                      ViewGroup group = (ViewGroup) view.getParent();
                      group.removeView(view);
                      FrameLayout contain = (FrameLayout) v;
                      contain.addView(view);
                      view.setX(x - (view.getWidth()/2));
                      view.setY(y - (view.getHeight()/2));
                      view.setVisibility(View.VISIBLE);
                  }//end if
                  else
                  {
                      View view = (View) event.getLocalState();
                      view.setVisibility(View.VISIBLE);
                  }//end else
                  break;
  
              default:
                      break;
          }//end switch
          return true;
      }//end onDrag function
  }//end ColonyHutDrag class
  </code></pre>
  
  <p>Thanks for any help in advance.</p>