我在表面视图上编写了一个带触摸监听器的代码来移动对象并且它工作得很好,当我在长按单击监听器上插入时,触摸监听器停止运行良好,即使我没有触摸它也会移动对象。长时间点击打开对话框。
on create:
sf = new SurfaceView(this);
sf.setOnTouchListener(this);
sf.setOnLongClickListener(this);
长按:
public boolean onLongClick(View v) {
if (!changePositionMode){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.text_manager);
dialog.setTitle("Browser");
dialog.setCancelable(true);
dialog.show();
}
return false;
}
触摸监听器上的
public boolean onTouch(View v, MotionEvent event) {
Point p=new Point((int)event.getX(),(int)event.getY());
if (event.getAction()==MotionEvent.ACTION_DOWN){
}else if (object.isTouch(p)){
changePositionMode=true;
x=event.getX();
y=event.getY();
draw();
return true;
}
}
else if (event.getAction()==MotionEvent.ACTION_MOVE){
t.changeTamplatePosition(event.getX()-x,event.getY()-y);
x=event.getX();
y=event.getY();
draw();
return true;
}
else if (event.getAction()==MotionEvent.ACTION_UP){
changePositionMode=false;
}
return false;
}