I have a webview that you can pinch to zoom just fine. I added a context menu to allow you to reset the zoom in addition to pinching out. However if I pinch a second time to zoom in, the same exact call to reset the zoom does not appear to reset the view? I've tried the following in various combinations but can not get a consistent reset zoom to work Thoughts?
myfrag.getWebView().getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
myfrag.getWebView().getSettings().setBuiltInZoomControls(true);
myfrag.getWebView().scrollTo(0,0);
Not sure why but this works:
myfrag.getWebView().getSettings().setLoadWithOverviewMode(false); myfrag.getWebView().getSettings().setLoadWithOverviewMode(true);
myfrag.getWebView().setInitialScale(0);
Related
I've got a webview with following settings:
WebSettings s = getSettings();
s.setAllowFileAccess(true);
s.setSupportZoom(false);
s.setBuiltInZoomControls(false);
s.setDisplayZoomControls(false);
s.setDomStorageEnabled(true);
s.setJavaScriptCanOpenWindowsAutomatically(true);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
In my app, I allow the user to change between two modes of the page which is displayed: fit screen & zoomed.
To do that, I change the scale of the page using javascript.
It all worked great, but a new requirement came along: always allow the user to use pinch to zoom, nevermind the mode they view the page with.
So I have changed these two settings:
s.setSupportZoom(true);
s.setBuiltInZoomControls(true);
And voila, the user can use pinch to zoom.
Now, I have two places where I scale the page:
javascript where I change the content scale
java where I allow user to zoom in on the webview
This means, that when user switches to fit screen mode, I have to zoom out the webview. It took me a moment to figure out, since there's only zoomOut() method, which zooms out "a little bit", but fortunately it returns a boolean to indicate success or failure, so a simple:
while(webview.zoomOut()) {}
does the trick. The webpage is properly zoomed out and scaled.
There is, however, a VERY frustrating side effect: when changing to the fit screen mode, the webview suddenly zooms in a little bit. It is done with animation and lasts for about 500ms. It's done automatically, I don't have any code which would do that.
So the effect is: page zooms out to fit the screen immediately and zooms in by a little margin within 500ms.
I have removed my zoomOut code and didn't use the pinch to zoom in my tests, but the webview would still zoom in a bit after I change the content scale inside javascript.
The only way to remove this effect is to setSupportZoom(false) which disables pinch to zoom.
Did anyone came across a similar issue and know how to disable this automatic zoom in?
Thank you
s.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
try this !!
For an app I'm working on the user needs to be able to zoom in and out using pinch gestures, but only within a certain boundary.
There are multiple "levels" on which users can see the map and there should be a settable zoom boundary for each of these.
We got this working partially by resetting the camera back to the limit if pinching has brought it outside of it's boundaries, but the user shouldn't be able to pinch out/in of the boundaries at all.
Here's a video of how it's working now:
https://www.youtube.com/watch?v=WfAle_M-i0k
And how it should work is that once the camera is at the zoomlevel-limit, zooming out further shouldn't be possible.
This is important because we'll be drawing a lot of objects on the screen and the app crashes when it's zoomed out too far.
We're using the default pinch-zoom that comes with
mMap.getUiSettings().setZoomGesturesEnabled(true);
Is there a way to disable further zooming in/out when the boundary has been reached?
I don't see any other way of doing this that implementing zoom controls by yourself, i.e. setting
mMap.getUiSettings().setZoomGesturesEnabled(false);
and adding buttons on top of your map with actions with zoomBy inside (with respect to your zoom boundaries kept somewhere).
You may also check lite mode.
I have a list of webviews and I need to know when the user changes the zoom level in one webview in order to apply the new zoom in other webviews.
Currently I added the OnZoomListener interface and I have onZoom(int i), but it's called only when zoom is changed from zoom controls and I need to detect zoom changes when user uses fingers to change zoom.
setLoadWithOverviewMode(boolean) loads the WebView completely zoomed out and setUseWideViewPort(boolean) makes the Webview have a normal viewport. So use these methods to evaluate.
http://developer.android.com/reference/android/webkit/WebSettings.html
I am looking for a way to replicate the native WebView zoom on double-tap but triggered via a long press instead. As, with the double-tab zoom I'd like the zoom to scale centered around the point of touch and then be able to scale back out to the default zoom level programmatically.
I was thinking there might be a way to spoof the double-tap gesture to the WebView within the longpress handler and provide it the coordinates of the long press but I am unable to find a way to do it.
Can this be done?
Found a workable if a bit of a hacky solution to this based upon information found in this post:
Double tap Programmatically on WebView
I replaced the content of:
public void simulateDoubleTap()
{
simulateDoubleTapEvent(0);
simulateDoubleTapEvent(2);
simulateDoubleTapEvent(2);
simulateDoubleTapEvent(1);
simulateDoubleTapEvent(0);
}
With:
public void simulateDoubleTap()
{
simulateDoubleTapEvent(MotionEvent.ACTION_DOWN);
simulateDoubleTapEvent(MotionEvent.ACTION_UP);
simulateDoubleTapEvent(MotionEvent.ACTION_DOWN);
simulateDoubleTapEvent(MotionEvent.ACTION_UP);
}
And then added a call to simulateDoubleTap() from within my longpress handler. This seemed to work - but it was not 100% consistent. May want to play with adding some small delays between the events and see if that smooths it out. Also I noticed that when zooming in, things would work with a single event, but it was taking two triggers of the double-tap to zoom back out. This may be because of the gesture handler I am using, or some other issue, but generally this seems to do what I need.
I am using a WebView in Android. After loading a webpage I would like to use the on-screen Zoom out control. After one or two clicks it becomes grayed and no longer allows me to zoom out any further. When I call the zoomOut() function in code, it also does not zoom out any further.
What is limiting how much I can zoom out. I would expect to be able to zoom out much further than I am allowed - to the point of making the page too small to read. But, zoom out is disabled well before I reach this level of zoom.
Any help is greatly appreciated.
Thanks,
Barry.
You should probably do this myWebView.getSettings().setUseWideViewPort(true)
You'll then see that you can zoom out farther than what you usually see on default settings.
Take a look at WebView.setInitialScale(...) - I'm not sure if it will help you with what you want but setting it to 50, for example, will scale the WebView to 50% of its normal size. I think that will allow you to zoom in and then out again to the (initial) smaller size.
Hey Barry
The built in range for that zoomin and zoomout function is starts from 0.8 something that is the minimum value after this if you
will call the zoomout function it will return the false value and
maximum value for zoomin is upto 4.0 ,So these zoomin and zoomout
functions are of boolean type Like for a zoomin function wverytime you
call zoomin function it multiply with some factor and return true if
further zoomin is possible and whenever it reaches to the last point
that is 4.0 so it will return false and after that it will not zoom
in.