javascript 在 webview 中捏放大 [Android]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3820377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pinch Zoom in webview [Android]
提问by Roskvist
On my website, which is loaded in the webview, there is a map. There are also java scripts that detects double tap for zoom, dragging etc. But is it possible to have a javascript that detects the use of pinch zoom ? there are several examples of it working on an iphone, and on my website there is a script for the pinch zoom but it is only working on iphone.....
在我加载到 webview 的网站上,有一张地图。还有一些 java 脚本可以检测双击缩放、拖动等。但是是否有可能有一个 javascript 来检测捏缩放的使用?有几个它在 iphone 上工作的例子,在我的网站上有一个用于捏合缩放的脚本,但它只在 iphone 上工作.....
Is it possible to get it to work on Android ?
是否有可能让它在 Android 上运行?
Thanks
谢谢
采纳答案by Ryan Berger
There's an open-source library called android-pinchthat you can include in your project to enable pinch zoom if you switch your WebViewto a WebImageView. Here's an example of usage...
有一个名为android-pinch的开源库,如果您切换WebView到WebImageView. 这是一个使用示例...
// create the WebImageView object from xml
WebImageView img = (WebImageView) findViewById(R.id.main_pic);
// fetches the image in a background thread
img.setImageFromURL("http://www.mysite.com/mypicture.jpg");
// enable pinch-zoom abilities on the image
new PinchImageView(img);
回答by Jesse Black
When you would like to scale web content in you WebView and enable pinch and zoom, I prefer the simple android way.
当您想在 WebView 中缩放 Web 内容并启用捏合和缩放时,我更喜欢简单的 android 方式。
webView.getSettings().setBuiltInZoomControls(true);
and you can even hide the controls if you are using API 11 or higher
如果您使用 API 11 或更高版本,您甚至可以隐藏控件
webView.getSettings().setDisplayZoomControls(false)
回答by luisfer
It's not exactly in a webview, but in any layout, that I wrote a piece of code for detecting pinch in an Android view.
我写了一段代码来检测 Android 视图中的夹点,这并不完全是在 web 视图中,而是在任何布局中。
It took me days to find out a solution for this, so I made my own custom pinch gesture detector.
我花了几天时间才找到解决方案,所以我制作了自己的自定义捏合手势检测器。
You can see it in Github: http://github.com/luisfer/Neckar
你可以在 Github 上看到:http: //github.com/luisfer/Neckar
Hope it helps.
希望能帮助到你。

