这是我为onTouchListener制作的代码:
if(event.getAction() == MotionEvent.ACTION_UP) {
Log.i("", "double touch : " + timeLastTouch + "... time passed: " + (System.currentTimeMillis() - timeLastTouch));
if (System.currentTimeMillis() - timeLastTouch < 500) {
Log.i("", "double touch TRUE");
timeLastTouch = System.currentTimeMillis();
return true;
} else {
Log.i("", "double touch FALSE");
timeLastTouch = System.currentTimeMillis();
return false;
}
}else if(event.getAction() == MotionEvent.ACTION_DOWN) {
Log.i("", "double touch DOWN : " + timeLastTouch + "... time passed: " + (System.currentTimeMillis() - timeLastTouch));
if (System.currentTimeMillis() - timeLastTouch < 500) {
Log.i("", "double touch TRUE DOWN");
timeLastTouch = System.currentTimeMillis();
return true;
}else {
Log.i("", "double touch FALSE DOWN");
return false;
}
}else {
timeLastTouch = System.currentTimeMillis();
Log.i("","double touch ELSE FALSE");
return false;
}
但它不起作用。 此视图位于“曲面”视图上。现在我只需要将事件发送到SurfaceView进行捏合(捏缩放) 现在我尝试制作逻辑,这样如果它有双触,那么我返回true(它已经消耗了触摸,因此表面视图,没有得到触摸)。 但如果我这样做,捏缩放也不起作用。 如果我删除这个逻辑,捏缩放,工作,所以我添加了一些日志,并遵循它们。我注意到,对于捏缩放,你得到2个向下事件,并且只有在调用ACTION_MOVE之后。据推测,因为当你捏缩放时,你放下2个手指,然后放大。我的问题是我的代码正在设置它,第二个Action_down消耗触摸,这意味着缩放的缩放不会启动。任何想法如何解决这个问题?
答案 0 :(得分:0)
我确实设法做到了这一点,具有以下逻辑:
viewTop.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("","double touch event action: ===========================");
Log.i("","double touch event action:" + event.getAction());
if(event.getAction() == MotionEvent.ACTION_DOWN) {
Log.i("", "double touch DOWN : " + timeLastTouch + "... time passed: " + (System.currentTimeMillis() - timeLastTouch) + "..... location diff: " + (event.getX() - xLastTouch));
if (System.currentTimeMillis() - timeLastTouch < 1000 && Math.abs(event.getX() - xLastTouch) < 150 && Math.abs(event.getY() - yLastTouch) < 150) {
Log.i("", "double touch TRUE DOWN");
timeLastTouch = System.currentTimeMillis();
xLastTouch = event.getX();
yLastTouch = event.getY();
return true;
} else {
timeLastTouch = System.currentTimeMillis();
xLastTouch = event.getX();
yLastTouch = event.getY();
Log.i("", "double touch FALSE DOWN");
return false;
}
}else if(event.getAction() == MotionEvent.ACTION_UP) {
timeLastTouch = System.currentTimeMillis();
xLastTouch = -1f;
yLastTouch = -1f;
return false;
}else {
timeLastTouch = System.currentTimeMillis();
xLastTouch = event.getX();
yLastTouch = event.getY();
Log.i("","double touch ELSE FALSE");
return false;
}
}
});
但是,如果我双击,第二个水龙头在另一个地方,它就会发生。对此并不那么开心,所以我需要更多地了解这一点,所以我还没有接受这个答案。在捏捏action_move之前,我需要知道我是否消耗了第二个Action_Down。