views:

89

answers:

1

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

+1  A: 

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
}

}

CodeFusionMobile
Thanks for your reply. I am familar with using the ScaleGestureDetector and passing the MotionEvent to it as you have depicted in the code above. My appologies if I'm wrong but the above code wont actually scale the WebView? Since there is no setScale() on the WebView how can i perform the zooming using the onScale method in the detector?
Bear