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