Drag and Drop out of Transparent Panel Android
<p>I am implementing drag an drop method.
I am trying to drag image out of transparent panel into the drag layer view, but it throws an error and force close. </p>

<p>The error from logcat says: Given view not child of com.example.drag.DragLayer. </p>

<p>The xml uses the DragLayer class.
Whats wrong? And how to solve it?</p>

<p>Here are the codes:
    "XML"
    </p>

<pre><code>&lt;com.example.drag.DragLayer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

android:id="@+id/drag_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"&gt;

&lt;com.example.drag.TransparentPanel
android:id="@+id/popup_window"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left"
android:padding="1px"
android:background="#ffffff"&gt;

&lt;ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"&gt;
&lt;LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="30px"
android:orientation="vertical"&gt;
&lt;TextView
 android:id="@+id/Text1"  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/&gt;
&lt;ImageView
android:id="@+id/Image1"
android:src="@drawable/icon1"
android:layout_weight="50" 
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /&gt;
&lt;ImageView
android:id="@+id/Image2"
android:src="@drawable/icon2"
android:layout_weight="50" 
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /&gt;

&lt;/LinearLayout&gt;
&lt;/ScrollView&gt;
&lt;/com.example.drag.TransparentPanel&gt;
&lt;/com.example.drag.DragLayer&gt;
</code></pre>

<p>Here are the codes: "DragLayer.java"</p>

<pre><code>public class DragLayer extends MyAbsoluteLayout 
implements DragSource, DropTarget
{
DragController mDragController;

   public DragLayer (Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void setDragController(DragController controller) {
    mDragController = controller;
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return mDragController.onInterceptTouchEvent(ev);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return mDragController.onTouchEvent(ev);
}

@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
    return mDragController.dispatchUnhandledMove(focused, direction);
}

public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
    DragView dragView, Object dragInfo)
{
View v = (View) dragInfo;
toast ("DragLayer2.onDrop accepts view: " + v.getId ()
      + "x, y, xO, yO :" + new Integer (x) + ", " + new Integer (y) + ", "
      + new Integer (xOffset) + ", " + new Integer (yOffset));

int w = v.getWidth ();
int h = v.getHeight ();
int left = x - xOffset;
int top = y - yOffset;
DragLayer.LayoutParams lp = new DragLayer.LayoutParams (w, h, left, top);
this.updateViewLayout(v, lp);
}

public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
    DragView dragView, Object dragInfo)
{
}

public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
    DragView dragView, Object dragInfo)
{
}

 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
    DragView dragView, Object dragInfo)
{
}

public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
    DragView dragView, Object dragInfo)
{
return true;
}

 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int  

  yOffset,
        DragView dragView, Object dragInfo, Rect recycle)
 {
return null;
}

public void toast (String msg)
{
if (!DragActivity.Debugging) return;
Toast.makeText (getContext (), msg, Toast.LENGTH_SHORT).show ();
} // end toast


} // end class
</code></pre>
