我正在使用此代码,它完全按照我的意愿工作.但是我必须在双击时实现另一个功能,并且想要禁用双击缩放(但保持缩放缩放功能).
webView.getSettings().setLoadWithOverviewmode(true); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setSupportZoom(true); webView.setInitialScale(1);
试图手动计算比例,没有运气(这感觉很复杂).
Disable Double Tap Zoom/Unzoom on a webview
Android Webview – Webpage should fit the device screen
有没有办法使用setUseWideViewPort和Zoomcontrolls但只禁用或覆盖双击缩放?
解决方法
最好的解决方案,只需从MyWebView扩展您的WebView
public class HelpWebView extends WebView { private GestureDetector gestureDetector; private AtomicBoolean mPreventAction = new AtomicBoolean(false); private AtomicLong mPreventActionTime = new AtomicLong(0); public HelpWebView(Context context) { super(context); gestureDetector = new GestureDetector(context,new GestureListener()); } public HelpWebView(Context context,AttributeSet attrs) { super(context,attrs); gestureDetector = new GestureDetector(context,AttributeSet attrs,int defStyle) { super(context,attrs,defStyle); gestureDetector = new GestureDetector(context,int defStyle,boolean privateBrowsing) { super(context,defStyle,privateBrowsing); gestureDetector = new GestureDetector(context,new GestureListener()); } @Override public boolean onTouchEvent(MotionEvent event) { int index = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; int pointId = event.getPointerId(index); // just use one(first) finger,prevent double tap with two and more fingers if (pointId == 0){ gestureDetector.onTouchEvent(event); if (mPreventAction.get()){ if (System.currentTimeMillis() - mPreventActionTime.get() > ViewConfiguration.getDoubleTapTimeout()){ mPreventAction.set(false); } else { return true; } } return super.onTouchEvent(event); } else { return true; } } private class GestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onDoubleTap(MotionEvent e) { mPreventAction.set(true); mPreventActionTime.set(System.currentTimeMillis()); return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { mPreventAction.set(true); mPreventActionTime.set(System.currentTimeMillis()); return true; } } }