在 webview 上禁用双击缩放/取消缩放 [英] Disable Double Tap Zoom/Unzoom on a webview
问题描述
在 Android 上,我使用 webview 来显示由 API flot 设计的图表.
On Android, I'm am using a webview to display a chart designed by the API flot.
我正在使用此代码:
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.graphique);
// Get a reference to the declared WebView holder
WebView webview = (WebView) this.findViewById(R.id.webView1);
// Get the settings
WebSettings webSettings = webview.getSettings();
// Enable Javascript for interaction
webSettings.setJavaScriptEnabled(true);
// Make the zoom controls visible
//webSettings.setBuiltInZoomControls(true);
// Allow for touching selecting/deselecting data series
webview.requestFocusFromTouch();
// Set the client
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.setBackgroundColor(0);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
// Load the URL
webview.loadUrl("file:///android_asset/graph.html");
即使开始时宽度和高度不同,图形也能正确显示并填充整个 webview(感谢 setLoadWithOverviewMode(true) 和 setUseWideViewPort(true)).
The graph is displayed correctly and fills the entire webview even if the width and height are not the same at start (thanks to setLoadWithOverviewMode(true) and setUseWideViewPort(true)).
但用户仍然可以通过双击图形来缩放和取消缩放.
But the user can still zoom and unzoom the graph by double tapping on it.
我想阻止此操作,我尝试将我的 webview 设置为 clickable=false、focusable=false 和 focusableintouchmode=false 但它不起作用.
I want to prevent this action, I tried to put my webview to clickable=false, focusable=false and focusableintouchmode=false but it doesn't work.
我也试过这个:
webview.getSettings().setBuiltInZoomControls(false);
但它不起作用.你有什么线索吗?
But it doesn't work. Do you have any clue ?
推荐答案
尝试设置
webView.getSettings().setUseWideViewPort(false);
并手动处理缩放以适应宽度..
and deal with scale manually to fit the width..
这篇关于在 webview 上禁用双击缩放/取消缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!