Android Webview initial zoom out

前端 未结 6 903
失恋的感觉
失恋的感觉 2021-02-07 00:58

I\'m using a webview in my android app, at the moment when the app is started the website is zoomed in quite a lot, i want it to be zoomed out to fit the width of the screen. I

相关标签:
6条回答
  • 2021-02-07 01:01

    This zooms out so that the content (an SVG in my case) fits on the screen but does not make unnecessary space.

    webView.getSettings().setUseWideViewPort(true);
    webView.setInitialScale(1);
    
    0 讨论(0)
  • 2021-02-07 01:06
        //This the the enabling of the zoom controls 
        webView.getSettings().setBuiltInZoomControls(true);
    
        //This will zoom out the WebView
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.setInitialScale(1);
    
    0 讨论(0)
  • 2021-02-07 01:09

    For Kit Kat and later devices you need to set the viewport meta tag in the headers of the HTML page loaded by your WebView in order to prevent the default zoom in behavior.

    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    
    0 讨论(0)
  • 2021-02-07 01:14

    use the webSettings class to set the zoom level...

    webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    
    0 讨论(0)
  • 2021-02-07 01:15
    webview.getSettings().setLoadWithOverviewMode(true);    
    

    This will cause the webview to be zoomed out initially.

    webview.getSettings().setUseWideViewPort(true);
    

    The Webview will have a normal viewport (like desktop browser), when false the webview will have a viewport constrained to it's own dimensions.

    EDIT: With the introduction of "Chrome web view" in Android KitKat, this code might not work.

    0 讨论(0)
  • 2021-02-07 01:17

    Try this:

        webView.setInitialScale(50);
        webPlanSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        webPlanSettings.setUseWideViewPort(true);
    
    0 讨论(0)
提交回复
热议问题