Android Drag and drop of button
<p>I am working in android, I am using a button. Now I want to perform drag and drop of this button.</p>

<p>This is my main.xml</p>

<pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
 &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/ll_first"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
&gt;

 &lt;Button  
   android:id="@+id/btn"
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
    android:text="drag me"
  /&gt;
 &lt;/LinearLayout&gt;
</code></pre>

<p>And this is my code to move this button on mouse drag:-</p>

<pre><code>public class DragdropActivity extends Activity implements OnTouchListener {

private final static int START_DRAGGING = 0;
private final static int STOP_DRAGGING = 1;

private Button btn;

private int status;

private ImageView image;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btn = (Button) findViewById(R.id.btn);
    btn.setDrawingCacheEnabled(true);
    btn.setOnTouchListener(this);

}

@Override
public boolean onTouch(View view, MotionEvent me) {
    if (me.getAction() == MotionEvent.ACTION_DOWN) {
        status = START_DRAGGING;


    }
    if (me.getAction() == MotionEvent.ACTION_UP) {
        status = STOP_DRAGGING;
        Log.i("Drag", "Stopped Dragging");
    } else if (me.getAction() == MotionEvent.ACTION_MOVE) {
        if (status == START_DRAGGING) {
            System.out.println("Dragging");
            Log.v("***Drag and drop **",
                    "me.getRawX and Y = " + me.getRawX() + " "
                            + me.getRawY());
            Log.v("***Drag and drop **",
                    "image position = " + image.getLeft() + " "
                            + image.getRight());
     btn.setPadding((int) me.getRawX(), (int) me.getRawY(), 0,0); //this is not working fine. 


            btn.invalidate();
        }
    }
    return false;
}
</code></pre>

<p>}</p>

<p>I think <code>btn.setPadding()</code> is not working correctly, please suggest me what should I do so that the button can easily move to the position of mouse or gesture touch ?</p>
