本文介绍了在没有设置限制的情况下在Android Webview上进行放大/缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目中,我需要我的用户能够滚动和放大大型SVG图片.我遇到的一个主要问题是android WebView类对放大和缩小的限制.我有什么办法可以根据自己的喜好删除或更改这些限制?标准的缩放控件似乎不支持释放这些边界.

In my current project I need my users to be able to scroll over and zoom in on large SVGImages. A major problem i encountered though, is the limit the android WebView class puts on zooming in and out. Is there any way I can remove or change these limits to my own likings?The standard zoom controls do not seem to support releasing these boundries.

如果我的问题不清楚,或者需要详细说明问题,请随时询问.

If my question is unclear, or if I need to elaborate on my question do not hesitate to ask.

问候,沃塔(Wottah)

Greets,Wottah

推荐答案

由于似乎没有人提供与使用反射不同的解决方案-我目前不知道有任何替代方案-我写了一篇简短的文章该代码段说明了如何绕过放大操作的上限.

Since no one seems to have come up with a different solution than using reflection - I'm not aware of any alternatives at this point - I wrote up a quick code snippet that illustrates how to bypass the upper limit on the zoom-in action.

请注意,下面的代码仅适用于ICS,可能仅适用于Honeycomb,但我目前没有平板电脑可以检查内部工作方式是否依赖于同一ZoomManager类. Gingerbread,Froyo和Eclair似乎都或多或少地直接在WebView类中实现了缩放功能.在下面的示例中,添加一些代码以同时考虑这些操作系统应该相当容易.

Note that the code below will only work on ICS, and possibly Honeycomb, but I currently don't have a tablet lying around to inspect if the inner workings rely on the same ZoomManager class. Gingerbread, Froyo and Eclair all appear to implement the zooming functionality more or less directly in the WebView class. With the example below it should be fairly easy to add some code to also take those operating systems into account.

// just set an Activity's content view to a single WebView for this test
WebView mWebview = new WebView(this);
setContentView(mWebview);

// retrieve the ZoomManager from the WebView
Class<?> webViewClass = mWebview.getClass();
Field mZoomManagerField = webViewClass.getDeclaredField("mZoomManager");
mZoomManagerField.setAccessible(true);
Object mZoomManagerInstance = mZoomManagerField.get(mWebview);

// modify the "default max zoom scale" value, which controls the upper limit
// and set it to something very large; e.g. Float.MAX_VALUE
Class<?> zoomManagerClass = Class.forName("android.webkit.ZoomManager");
Field mDefaultMaxZoomScaleField = zoomManagerClass.getDeclaredField("mDefaultMaxZoomScale");
mDefaultMaxZoomScaleField.setAccessible(true);
mDefaultMaxZoomScaleField.set(mZoomManagerInstance, Float.MAX_VALUE);

这篇关于在没有设置限制的情况下在Android Webview上进行放大/缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:48