我的布局需要具有捏缩放功能,并且在该布局内部还有许多具有咔嗒功能的子(imageview)。点击功能将打开另一个活动。
我已使用此代码创建自定义布局https://gist.github.com/klarson2/4f737adf7f2577dc0fd09efb85eff3b1
但问题是,当第一根手指触摸孩子时,第二根手指触摸任何不会缩放的手指。
然后我在缩放代码(https://gist.github.com/klarson2/4f737adf7f2577dc0fd09efb85eff3b1)中放入了这段代码:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
switch (ev.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
startClickTime = Calendar.getInstance().getTimeInMillis(); //start time when first finger land
startX = ev.getX() - prevDx;
startY = ev.getY() - prevDy;
break; //return false will go to frag
case MotionEvent.ACTION_POINTER_DOWN:
clickDuration = Calendar.getInstance().getTimeInMillis() - startClickTime;
if(clickDuration > MAX_CLICK_DURATION){
// letting go from drag or zooming
Log.i("Zoom1", " action pointer down test");
return true; // remain at zoomlayout and do ontouch
}
break;
case MotionEvent.ACTION_UP:
clickDuration = Calendar.getInstance().getTimeInMillis() - startClickTime;
Log.i("Zoom1", " action up test");
if(clickDuration < MAX_CLICK_DURATION){
return false;
}
else {
// letting go from drag or zooming
return true;
}
case MotionEvent.ACTION_MOVE:
clickDuration = Calendar.getInstance().getTimeInMillis() - startClickTime;
if(clickDuration >= MAX_CLICK_DURATION){
// to long on move, definitely is drag
mode = Mode.DRAG;
return true;
}
else {
return false;
}
}
return false;
}
然后出现的另一个问题是两个手指触摸孩子并捏缩放。变焦偏移。
这是应用程序如何运行的想法。但它会起作用吗?我尝试了很多方法,但最终出现了很多错误。谁能帮我吗。谢谢。