2
我写了一个代码与触摸监听器在表面视图移动对象和它的工作很好,当我插入长按听众触摸监听器停止工作良好和对象移动即使我没有碰它。长按一下即可打开对话框。触摸监听器和长按听众
上创建:
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;
}
请参阅此答案,了解如何将触摸事件传递给longClickListener:http://stackoverflow.com/questions/7387572/android-ontouch-with-onclick-and-onlongclick – Sanders
长按好?问题在于触摸事件? –
问题是触摸事件 – tzahibs