【发布时间】:2025-12-15 02:35:01
【问题描述】:
我正在使用一个带有 on drag 监听器的简单应用程序来将一个按钮从屏幕的一半拖动到另一半。我可以在任何模拟器或设备上很好地拖动元素,并使用 Monkey Runner 实现的拖动功能。当我尝试使用葫芦使用“performAction('drag',50,30,25,75,15)”(和drag_coordinates)在屏幕上拖动元素时,出现拖动阴影,然后立即停止拖动动作(见图片)。
任何其他拖动(不是在可拖动元素上)都有效,包括那些打开抽屉或“移动”画布上绘制的矩形的那些。我试图让 Drag Shadow 为空,以防它干扰拖动。然后,损坏的拖动动画会阻止与葫芦的任何其他交互,除非我与设备交互以取消拖动。
有没有其他人注意到在屏幕上拖动元素/对象并在拖动开始时冻结它的类似问题?我意识到 Calabash 在其核心使用机器人,所以如果这些测试框架中的任何一个都适用于此。我正在使用最新的 calabash-android-0.4.21,甚至刚刚尝试了 beta 0.5 版本。
MainActivity 代码: `package com.example.dragndrop;
import android.os.Bundle;
import android.app.Activity;
import android.content.ClipData;
import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
Button drag;
LinearLayout drop;
TextView text,sucess;
int total , failure = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drag = (Button)findViewById(R.id.one);
drop = (LinearLayout)findViewById(R.id.toplinear);
text = (TextView)findViewById(R.id.Total);
sucess = (TextView)findViewById(R.id.Sucess);
sucess.setText("Sucessful Drops :"+(total - failure));
text.setText("Total Drops: "+total);
drag.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
// TODO Auto-generated method stub
final int action = event.getAction();
switch(action) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DROP:{
failure = failure+1;
return(true);
}
case DragEvent.ACTION_DRAG_ENDED:{
total = total +1;
int suc = total - failure;
sucess.setText("Sucessful Drops :"+suc);
text.setText("Total Drops: "+total);
return(true);
}
default:
break;
}
return true;
}});
drag.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1) {
// TODO Auto-generated method stub
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadow = new View.DragShadowBuilder(drag);
v.startDrag(data, shadow, null, 0);
return false;
}
});
}
}`
【问题讨论】:
标签: android drag-and-drop drag robotium calabash