Cómo deshabilitar el desplazamiento / zoom suave en webView

I have custom class:

public class CustomWebView extends WebView {

and I implemented own zoom method (using zoomIn() and zoomOut()), but it's ugly, there is a delayed zoom animation.

Scrolling in webView the same: after fingers up, scroll still working for some time.

How to disable this smooth animations?

preguntado el 08 de noviembre de 11 a las 14:11

Just curious, are you implementing this using OnTouchListener, OnMotionEvent, or GestureListener? I've found that OnMotionEvent is the most reliable of these three for implementing custom events. -

I added my CustomWebView class as answer -

2 Respuestas

Call this method on your CustomWebView objeto

mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);

Fuente: http://developer.android.com/reference/android/view/View.html#setOverScrollMode(int)

respondido 26 nov., 11:20

My Custom webView:

public class CustomWebView extends WebView {
    static final int NONE = 0;
    static final int DRAG = 1;
    static final int ZOOM = 2;
    int mode = NONE;

    PointF start = new PointF();
    PointF mid = new PointF();
    float oldDist = 1f;
    float scale = 0f;
    float oldscale = 0f;
    int displayHeight;

        public CustomWebView(Context context) {
            super(context);
        }

        public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        public CustomWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            boolean consumed = super.onTouchEvent(ev);

            if (isClickable())
                switch (ev.getAction() & MotionEvent.ACTION_MASK) {

                   case MotionEvent.ACTION_DOWN: 
                      start.set(ev.getX(), ev.getY());
                      mode = DRAG;
                      break;
                   case MotionEvent.ACTION_UP: 
                   case MotionEvent.ACTION_POINTER_UP: 
                      mode = NONE;
                      break;
                   case MotionEvent.ACTION_POINTER_DOWN: 
                      oldDist = spacing(ev);
                      if (oldDist > 5f) {
                         midPoint(mid, ev);
                         mode = ZOOM;
                      }
                      break;

                   case MotionEvent.ACTION_MOVE: 
                      if (mode == DRAG) { 
                      }
                      else if (mode == ZOOM) { 
                         float newDist = spacing(ev);
                         if (newDist > 5f) {
                            scale = newDist / oldDist; 
                            if(scale>1){
                                if(Math.abs(oldscale-scale)>0.3){
                                    zoomIn();
                                    oldscale = scale;
                                }
                            }
                            System.out.println(scale);
                            if(scale<1){
                                if((getContentHeight()*getScale()>displayHeight)){
                                    zoomOut();
                                    System.out.println(getScale());
                                }
                            }
                         }
                      }
                      break;
                   }
            return consumed;
        }

        private float spacing(MotionEvent event) {
               float x = event.getX(0) - event.getX(1);
               float y = event.getY(0) - event.getY(1);
               return FloatMath.sqrt(x * x + y * y);
            }

            private void midPoint(PointF point, MotionEvent event) {
               float x = event.getX(0) + event.getX(1);
               float y = event.getY(0) + event.getY(1);
               point.set(x / 2, y / 2);
            }
}

respondido 09 nov., 11:12

You should edit your question with this code, not add an answer. - ciego

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.