Code example for DragEvent

Methods: getAction, getX, getY

0
        return true; 
    } 
	private  class MyDragListener implements OnDragListener {
	    @Override 
	    public boolean onDrag(View v, DragEvent event) {
	      int action = event.getAction();
	      switch (action) {
	      case DragEvent.ACTION_DRAG_STARTED:
	        // Do nothing 
	        break; 
	      case DragEvent.ACTION_DRAG_ENTERED:
	         
	        break; 
	      case DragEvent.ACTION_DRAG_EXITED:
	         
	        break; 
	      case DragEvent.ACTION_DROP:
	        // Dropped, reassign View to ViewGroup 
	        RelativeLayout container = (RelativeLayout) v;
	        TextView tx = new TextView(MainActivity.this);
	        RelativeLayout.LayoutParams lpPosicion = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	        int left = ((int)(event.getX()/150))*150;
	        int top = ((int)(event.getY()/50))*50;
	        lpPosicion.setMargins(left, top, 0, 0);
	        tx.setLayoutParams(lpPosicion);
	        tx.setBackgroundColor(Color.BLUE);
	        tx.setText("Test");
	        container.addView(tx);