【问题标题】:Disable Double Tap Zoom/Unzoom on a webview在 web 视图上禁用双击缩放/取消缩放
【发布时间】:2012-02-19 13:57:29
【问题描述】:

在 Android 上,我正在使用 webview 来显示由 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))。

但用户仍然可以通过双击图表来缩放和取消缩放图表。

我想阻止此操作,我尝试将我的 webview 设置为 clickable=false、focusable=false 和 focusableintouchmode=false,但它不起作用。

我也试过这个:

webview.getSettings().setBuiltInZoomControls(false);

但它不起作用。你有什么线索吗?

【问题讨论】:

标签: android webview zooming


【解决方案1】:

尝试设置

webView.getSettings().setUseWideViewPort(false);

并手动处理比例以适应宽度..

【讨论】:

  • 我认为这可行,但如何手动缩放宽度?我的图形宽度和高度无法定义,我可以直接从我的代码中缩放它吗?
  • 非常感谢!正是我需要的。
猜你喜欢
  • 2022-08-12
  • 1970-01-01
  • 1970-01-01
  • 2020-05-01
  • 2018-02-20
  • 1970-01-01
  • 1970-01-01
  • 2015-10-07
  • 1970-01-01
相关资源
最近更新 更多