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 !!
Related
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);
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 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.
I noticed that the position of the builtInZoomControls in WebView (bottom, horizontal right) is not consistent with the default position in the MapView (bottom, horizontal center).
1) Why is that not consistent? (Probably a question to be asked to Google)
2) Is there a way to horizontal center the builtInZoomControls of the WebView without applying custom Zoom controls? Or is that the only way?
From my experience with the Android UI, here's what i've noticed
When using a Maps activity, there is really no reason to align to the right, you are looking at a map, ie. a 2D surface that can be scrolled at will.
When browsing a website, most content starts at the left and runs right.
So, placing the control in the lower right while browsing the web makes a lot of sense, to keep it out of the way, when using maps (where the zoom control is more important), the control should be more prominent, thus in the center, where it still does not get in the way here.
Upon first reading your post, I was going to suggest using a custom zoom control, but I realize that you have thought about this already. If having centered controls is essential to your application, a custom control seems to be the route I'd take.
When viewing maps in a WebView you are actually using the Browser app to view the Map Tiles. In order to change the zoom controls when in Web View you would have to manipulate the zoom controls of the browser being used to view the Map Tiles.
You should try manipulating the WebView zoom controls and not the MapView zoom controls.