抓住并拖动elemnets

时间:2015-04-28 14:04:30

标签: android automated-tests calabash calabash-android

我有一张图片ID(item_image),我想把它拿到我的购物车上,购物车的ID是(view_cart)。

我尝试了perform_action('drag',fromX,toX,fromY,to,steps),我使用pan(“* id:'element'”,:right)来保存图像并将其拖动到右边

你能帮我吗?

1 个答案:

答案 0 :(得分: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;
}
});

试试这个。