Code example for ImageView

Methods: setImageBitmap, getLayoutParams

1
 
	// move the drag view 
	private void drag(int x, int y) {
		if (mDragView != null) {
			WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) mDragView
					.getLayoutParams();
			layoutParams.x = x;
			layoutParams.y = y - mDragPointOffset;
			WindowManager mWindowManager = (WindowManager) getContext()
					.getSystemService(Context.WINDOW_SERVICE);
			mWindowManager.updateViewLayout(mDragView, layoutParams);
 
			if (mDragListener != null)
				mDragListener.onDrag(x, y, null);// change null to "this" when
													// ready to use 
		} 
	} 
 
	// enable the drag view for dragging 
	private void startDrag(int itemIndex, int y) {
		stopDrag(itemIndex);
 
		View item = getChildAt(itemIndex);
		if (item == null)
			return; 
		item.setDrawingCacheEnabled(true);
		if (mDragListener != null)
			mDragListener.onStartDrag(item);
 
		// Create a copy of the drawing cache so that it does not get recycled 
		// by the framework when the list tries to clean up memory 
		Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
 
		WindowManager.LayoutParams mWindowParams = new WindowManager.LayoutParams();
		mWindowParams.gravity = Gravity.TOP;
		mWindowParams.x = 0;
		mWindowParams.y = y - mDragPointOffset;
 
		mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
		mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
		mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
				| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
				| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
				| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
				| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
		mWindowParams.format = PixelFormat.TRANSLUCENT;
		mWindowParams.windowAnimations = 0;
 
		Context context = getContext();
		ImageView v = new ImageView(context);
		v.setImageBitmap(bitmap);
 
		WindowManager mWindowManager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		mWindowManager.addView(v, mWindowParams);
		mDragView = v;