launcher跨屏拖动item(GridView长按item进行拖动demo)

触发长按事件后浮动原理:

  windowParams = new WindowManager.LayoutParams();

  windowParams.gravity = Gravity.TOP | Gravity.LEFT;

  windowParams.x = x - itemWidth / 2;

  windowParams.y = y - itemHeight / 2;

  windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;

  windowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;

  ImageView iv = new ImageView(getContext());

  iv.setImageBitmap(bm);

  windowManager = (WindowManager) getContext().getSystemService(

  Context.WINDOW_SERVICE);// "window"

  windowManager.addView(iv, windowParams);

  拖动效果:

  if (dragImageView != null) {

  windowParams.alpha = 0.6f;

  windowParams.x = x - itemWidth / 2;

  windowParams.y = y - itemHeight / 2;

  windowManager.updateViewLayout(dragImageView, windowParams);

  }

原文地址:https://www.cnblogs.com/shanzei/p/2419373.html