Code example for RelativeLayout.LayoutParams

Methods: setMargins

0
	        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);
	        break; 
	      case DragEvent.ACTION_DRAG_ENDED:
	      default: 
	        break; 
	      } 
	      return true; 
	    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE