Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

android - Disable Double Tap Zoom/Unzoom on a webview

On Android, I'm am using a webview to display a chart designed by the API flot.

I'm using this code:

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

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.

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.

I tried this also :

webview.getSettings().setBuiltInZoomControls(false);

But it doesn't work. Do you have any clue ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try to set

webView.getSettings().setUseWideViewPort(false);

and deal with scale manually to fit the width..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...