有没有办法在 WebView 上隐藏和显示缩放控件?
我有两个观点。一种是WebView,另一种是ImageView。我为 WebView 设置了自动缩放控件,如下所示:
webview.getSettings().setBuiltInZoomControls(true);
我只是使用 GONE
和 Visible
更改两个视图的可见性。将视图从 WebView 更改为 ImageView 时,缩放控件在一段时间内不会失去可见性。
有没有可能隐藏和显示自动缩放控件的方法?
编辑:
我尝试了这些方法,但仍然不起作用。
webview.getZoomControls().setVisibility(View.GONE);
webview.getZoomControls().invalidate();
I have a two Views. One is a WebView and the other is an ImageView. I set the auto zoom controls for the WebView like so:
webview.getSettings().setBuiltInZoomControls(true);
I am just changing the visibility of both Views using GONE
and Visible
. While changing my View from WebView to ImageView, the zoom controls do not lose their visibility for some period of time.
Is there any possible way to hide and show the Autozoomcontrols?
Edit:
I tried these methods, but it's still not working.
webview.getZoomControls().setVisibility(View.GONE);
webview.getZoomControls().invalidate();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获取从 WebView.getZoomControls() 获得的视图,并将其作为子视图添加到 Web 视图旁边(或顶部)的布局中。不幸的是,它很老套, getZoomControls 已被弃用,并且除非您调用 WebSettings.setBuildInZoomControls(true) (这将添加您不想要的第二个缩放控件视图),否则您不会获得捏缩放,但它似乎可以工作。这是我执行此操作的代码,因为它的价值:
布局 xml:
Java (在活动内):
现在要使缩放消失,您可以设置 R.id.rl 的可见性(其中包含 WebView 和 FrameLayout,其中包含缩放控件)到RelativeLayout.GONE。
对于一个简单的解决方案:如果您的最低 Api 设置为级别 11(即 3.0 Honeycomb,因此不幸的是,这不太可能),您可以使用:
http://developer .android.com/reference/android/webkit/WebSettings.html#setDisplayZoomControls(boolean)
You can take the view you get from WebView.getZoomControls() and add it as a child to a layout beside (or on top of) the webview. Unfortunately it's hacky, getZoomControls is deprecated, and you don't get pinch zoom unless you call WebSettings.setBuildInZoomControls(true) (which will add a SECOND zoom controls view, which you don't want), but it seems to work. Here's my code to do this, for what it's worth:
Layout xml:
Java (within an activity):
Now to have the zoom disappear, you can set the visibility of R.id.rl (which contains the WebView and the FrameLayout containing the zoom conrols) to RelativeLayout.GONE.
For an unhacky solution: if your minimum Api is set to level 11 (which is 3.0 Honeycomb, so unfortunately this is unlikely), you can use:
http://developer.android.com/reference/android/webkit/WebSettings.html#setDisplayZoomControls(boolean)
我想这会起作用。
I suppose this will work.