Pinch Zoom in webview [Android]

别等时光非礼了梦想. 提交于 2019-12-03 12:50:18

There's an open-source library called android-pinch that you can include in your project to enable pinch zoom if you switch your WebView to a WebImageView. Here's an example of usage...

// 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);

When you would like to scale web content in you WebView and enable pinch and zoom, I prefer the simple android way.

webView.getSettings().setBuiltInZoomControls(true);

and you can even hide the controls if you are using API 11 or higher

webView.getSettings().setDisplayZoomControls(false)

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.

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

Hope it helps.

kikoso

This excellent tutorial shows how to implement the Pinch gesture.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!