WebView.getScale() is deprecated (but still usable)
The recommended way to get scale for webview is to use WebViewClient.onScaleChanged() http://developer.android.com/reference/android/webkit/WebViewClient.html#onScaleChanged(android.webkit.WebView, float, float)
I've added corresponding handler in my custom webview:
public class CustomWebView extends WebView {
public CustomWebView(Context context) {
super(context);
setWebViewClient(new WebViewClient() {
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
super.onScaleChanged(view, oldScale, newScale);
currentScale = newScale
}
});
}
And now the problem: the method not invoked (at least on my nexus 7) if I'm zoom in/zoom out using pinch, so it works good only if I use zoom controls button.
I'm developing for API level 17 and I ended up using the deprecated method getScale() for the same reason. WebViewClient.onScaleChanged() simply wasn't triggered when I changed the scale using pinch zoom in the WebView. I have a custom GestureListener in my extended WebView that behaves differently when the view is zoomed in (scale 1.0+). I couldn't reliably get the proper scale value when I set a class variable in onScaleChanged().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With