Question

HI,

Is it possible to support zooming of a WebView (similar to the default browser) when the user pinches and moves their fingers closer / further away. Im using 2.2 and tought this would be possible using the ScaleGestureDetector. THe problem is that I can't seem to find a method to set the scale. WebView.getScale() returns the current scale which changes through zoomIn() and ZoomOut() but I can't find setScale() or an option to set zooming by default and let the OS handle it.

Andy

Was it helpful?

Solution

Use:

webview.getSettings().setBuiltInZoomControls(true);

to do pinch zooming and put the default zoom in/out buttons on the screen.

OTHER TIPS

You need to implement the onTouchEvent(MotionEvent) in your WebView.

Then in that event, pass the MotionEvent to the ScaleGestureDetector so that it can process it, then call the super.

class ScalableWebView extends WebView implements ScaleGestureDetector.OnScaleGestureListener
{
    ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(this, this);

    public boolean onTouchEvent(MotionEvent event)
    {
        if(mScaleDetector.onTouchEvent(event))
             return true;

        return super.onTouchEvent(event);
    }

    boolean onScaleBegin(ScaleGestureDetector detector) 
    {
     //handle scale event begin
    }

    boolean onScale(ScaleGestureDetector detector) 
    {
     //handle scale event
    }

    boolean onScaleEnd(ScaleGestureDetector detector) 
    {
     //handle scale event end
    }

}

There is a setScale , try this :

webView.setInitialScale((int)(100 * webView.getScale());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top