我不确定为什么您的尝试没有奏效,但这是另一种方法:
不要GestureDetector.OnDoubleTapListener
在您的视图上实现,而是直接在ReaderView
您扩展的视图上实现它
public class ReaderView extends AdapterView<Adapter> implements
GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener,
ScaleGestureDetector.OnScaleGestureListener,
Runnable { ... }
然后OnDoubleTap
像这样覆盖方法
@Override
public boolean onDoubleTap(MotionEvent e) {
float previousScale = mScale;
mScale += (mScale == 1f) ? 2f : -2f;
float factor = mScale/previousScale;
View v = mChildViews.get(mCurrent);
if (v != null) {
// Work out the focus point relative to the view top left
int viewFocusX = (int)e.getX() - (v.getLeft() + mXScroll);
int viewFocusY = (int)e.getY() - (v.getTop() + mYScroll);
// Scroll to maintain the focus point
mXScroll += viewFocusX - viewFocusX * factor;
mYScroll += viewFocusY - viewFocusY * factor;
requestLayout();
}
return true;
}
您还必须覆盖这两种其他方法
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
从 Librelio Android 示例中获取此代码
https://github.com/libreliodev/android