最后,我决定使用ScaleGestureDetector
缩放功能和视图中的条件onTouchEvent()
来处理平移。我在缩放时设置了一个标志以防止平移。代码摘录包括在下面。它不像我可以同时缩放和平移那样流畅,但这是我可以接受的解决方案。
----在视图类中----
ScaleListener zoomListener = new ScaleListener();
public override bool OnTouchEvent(MotionEvent motion)
{
zoomListener.onTouchEvent(motion);
int actionMasked = motion.getActionMasked();
if (actionMasked == MotionEvent.ACTION_MOVE && motion.getPointersDown() > 1)
{
if (!_zoomMode)
{
// If more than one pointer is involved in a move event,
// and zoom mode is not set, we assume that the user is panning.
// A zoom gesture movement should be handled by the ScaleGestureDetector
doPan();
}
}
}
----内部班----
class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener
{
public boolean onScale(ScaleGestureDetector detector)
{
setZoomMode(true);
doZoom();
}
public void onScaleEnd(ScaleGestureDetector detector)
{
setZoomMode(false);
}
}