Drag And Drop textview on imageview in android
<p>I tried my best can anyone help to <strong>drag and drop textview</strong> on imageview in android</p>

<p>my xml with frame layout</p>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"&gt;

&lt;ImageView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:scaleType="center"
    android:src="@drawable/golden_gate" /&gt;

&lt;TextView
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dip"
    android:layout_gravity="center_horizontal|bottom"

    android:padding="12dip"

    android:background="#AA000000"
    android:textColor="#ffffffff"

    android:text="Golden Gate" /&gt;

&lt;/FrameLayout&gt;
</code></pre>

<p>i tried drag and drop text as below as i have used here linear layout the text is dragging in some part only not on image</p>

<pre><code>import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class DragNDropActivity extends Activity {
        private View selected_item = null;
        private int offset_x = 0;
        private int offset_y = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ViewGroup vg = (ViewGroup)findViewById(R.id.vg);
        vg.setOnTouchListener(new View.OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                                switch(event.getActionMasked())
                                {
                                        case MotionEvent.ACTION_MOVE:
                                                int x = (int)event.getX() - offset_x;
                                                int y = (int)event.getY() - offset_y;
                        int w = getWindowManager().getDefaultDisplay().getWidth() - 100;
                        int h = getWindowManager().getDefaultDisplay().getHeight() - 100;
                        if(x &gt; w)
                            x = w;
                        if(y &gt; h)
                            y = h;
                                         LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                                        new ViewGroup.MarginLayoutParams(
                                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                                        LinearLayout.LayoutParams.WRAP_CONTENT));
                                         lp.setMargins(x, y, 0, 0);
                                                selected_item.setLayoutParams(lp);
                                                break;
                                        default:
                                                break;
                                }
                                return true;
                        }
   });
      TextView img = (TextView)findViewById(R.id.img);
        img.setOnTouchListener(new View.OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                                switch(event.getActionMasked())
                                {
                                        case MotionEvent.ACTION_DOWN:
                                                offset_x = (int)event.getX();
                                                offset_y = (int)event.getY();
                                                selected_item = v;
                                                break;
                                        default:
                                                break;
                                }

                                return false;
                        }
                });
    }
}
</code></pre>
