你可以写你自己的WebView实现implemting OnGestureListener:
public class MyWebView extends WebView implements OnGestureListener
内声明GestureDetector:
private GestureDetector gestureDetector;
实现一个initWebView()方法,并调用它在这样的构造:
// Best you do this for every WebViewConstructor:
public AppWebView(Context context) {
super(context);
initWebView(); }
private void initWebView(){
gestureDetector = new GestureDetector(getContext(), this);
// Do any other customizations for your webview if you like.
}
现在实现OnGestureListene中的方法r和上双击事件返回true:
public boolean onSingleTapConfirmed(MotionEvent e) {
return false; //Nothing
}
public boolean onDoubleTap(MotionEvent e) {
return true; //Nothing
}
public boolean onDoubleTapEvent(MotionEvent e) {
return true; //Nothing
}
public boolean onDown(MotionEvent e) {
return false; //Nothing
}
public void onShowPress(MotionEvent e) {
//Nothing
}
public boolean onSingleTapUp(MotionEvent e) {
return false; //Nothing
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false; //Nothing
}
public void onLongPress(MotionEvent e) {
//Nothing
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false; //Nothing
}
最后重写网页视图中的onTouchEvent,让它穿过事件姿态探测器是这样的:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) return true;
return super.onTouchEvent(event);
}
这个工作通常不错,但有此解决方案存在1个基本缺陷:某些未被识别为DoubleTap事件的事件可能会导致您的webview缩放。
I'm仍在为一个解决方案,并会张贴我的进步在这里: WebView getting rid of double tap zoom.
Thx,看起来很有希望。我将接受它作为答案而不进行测试。我做了一个黑客,我完全禁用了缩放功能,将WebView传递给了HTML,并且适合JavaScript内的内容。不是很好,但它工作。 – SimonSays