【发布时间】:2016-11-10 19:02:05
【问题描述】:
我有一个自定义布局捏缩放代码作为处理点击功能的父和子布局。因此我使用触摸拦截,但问题是它不知道何时单击或拖动。
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
switch (ev.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
startClickTime = System.currentTimeMillis(); //start time when first finger land
Log.i("Zoom", " actionDown");
if ( scale > MIN_ZOOM){
mode = Mode.DRAG;
startX = ev.getX() - prevDx;
startY = ev.getY() - prevDy;
}
return false; //go to child layout
case MotionEvent.ACTION_POINTER_DOWN:
mode = Mode.ZOOM;
return true;
case MotionEvent.ACTION_UP:
long clickDuration = System.currentTimeMillis() - startClickTime;
mode = Mode.NONE;
if(clickDuration < MAX_CLICK_DURATION){
return false;
}
else {
// letting go from drag or zooming
return true;
}
case MotionEvent.ACTION_MOVE:
clickDuration = System.currentTimeMillis() - startClickTime;
if (clickDuration > MAX_CLICK_DURATION){
return true;
}
else {
return false;
}
}
return false;
}
在我的子布局中点击功能:
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// primary finger down
return true;
case MotionEvent.ACTION_POINTER_DOWN:
// non-primary finger down
return false;
case MotionEvent.ACTION_CANCEL:
return false;
case MotionEvent.ACTION_UP:
// primary finder up
Intent intent = new Intent(context, DeviceActivity.class);
context.startActivity(intent);
return true;
case MotionEvent.ACTION_POINTER_UP:
// non-primary finger up
return false;
}
那么有没有办法区分拖拽和点击呢。
【问题讨论】:
标签: android pinchzoom android-gesture