0

I have ID for an image (item_image) and I want to hold it and drag it to my cart which the id for the cart is (view_cart).

I tried the perform_action('drag',fromX,toX,fromY,toY,steps) and I used the pan("* id:'element'", :right) which it hold the image and drag it to right.

Could you help me please?

mhu
  • 17,720
  • 10
  • 62
  • 93

1 Answers1

1
floctingicon.setOnTouchListener(new View.OnTouchListener() {
 private WindowManager.LayoutParams paramsF = params;
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;

@Override
public boolean onTouch(View v, MotionEvent event) {

 switch (event.getAction()) {
 case MotionEvent.ACTION_DOWN:

  // Get current time in nano seconds.

  initialX = paramsF.x;
  initialY = paramsF.y;
  initialTouchX = event.getRawX();
  initialTouchY = event.getRawY();
  break;
 case MotionEvent.ACTION_UP:
  break;
 case MotionEvent.ACTION_MOVE:
  paramsF.x = initialX
    + (int) (event.getRawX() - initialTouchX);
  paramsF.y = initialY
    + (int) (event.getRawY() - initialTouchY);
  windowManager.updateViewLayout(floctingicon, paramsF);
  break;
 }
 return false;
}
});

try this.

Ankit Kumar
  • 3,663
  • 2
  • 26
  • 38