Code example for RelativeLayout

Methods: addView, setVisibility

0
			updatePos(event, v, params, imageView);
			break; 
		} 
		case MotionEvent.ACTION_UP: {
			updatePos(event, v, params, imageView);
			container.setVisibility(View.GONE);
			onElementDropped(event.getRawX(), event.getRawY());
			break; 
		} 
		case MotionEvent.ACTION_DOWN: {
			updatePos(event, v, params, imageView);
			container.setVisibility(View.VISIBLE);
			break; 
		} 
		} 
		return true; 
	} 
 
	public abstract void onElementDropped(float rawX, float rawY);
 
	public void updatePos(MotionEvent event, View v, LayoutParams params,
			ImageView imageView) {
		params.topMargin = (int) event.getRawY() - (v.getHeight());
		params.leftMargin = (int) event.getRawX() - (v.getWidth() / 2);
		imageView.setLayoutParams(params);
	} 
 
	private ImageView getImageView(View source, Activity activity,
			RelativeLayout c, LayoutParams params) {
		if (imageView == null) {
			final Bitmap bitmap = IO.loadBitmapFromView(source);
			final Paint shadowPaint = new Paint();
			shadowPaint.setAlpha(180);
			// http://stackoverflow.com/questions/7048941/how-to-use-the-lightingcolorfilter-to-make-the-image-form-dark-to-light 
			shadowPaint.setColorFilter(new LightingColorFilter(0x11333333,
					0x00000000)); 
 
			imageView = new ImageView(activity) {
 
				@Override 
				protected void onDraw(Canvas canvas) {
					// First draw shadow 
					float dist = 2;
					canvas.drawBitmap(bitmap, dist, dist, shadowPaint);
					// then draw normal image view 
					super.onDraw(canvas);
				} 
			}; 
			imageView.setImageBitmap(bitmap);
			c.addView(imageView);
		} 
		return imageView;
	} 
 
	private android.widget.RelativeLayout.LayoutParams getDragDropContainerParams(
			Context context) {
		if (params == null) {
			params = new LayoutParams(LayoutParams.WRAP_CONTENT,
					LayoutParams.WRAP_CONTENT);
		} 
		return params;
	} 
 
	private RelativeLayout getDragDropContainer(Activity activity) {
		if (container == null) {
			container = new RelativeLayout(activity);
			activity.addContentView(container, params);
		} 
		return container;
	}