Set zoom for Webview

前端 未结 9 1096
忘了有多久
忘了有多久 2020-11-30 02:26

I have a WebView and 2 urls to open it it. What I want to do is, when i set a zoom level for 1st url, and then i go to 2nd url, it should also have the same zoom level. Righ

相关标签:
9条回答
  • 2020-11-30 02:49

    this will be applicable in this scenario i believe

    mWebView.setInitialScale(ZOOM_LEVEL);
    

    where ZOOM_LEVEL for example can be 25 for 25% 150 for 150%

    0 讨论(0)
  • 2020-11-30 02:49

    @John gave the right idea, but one command is enough, since you can get and set before the page shows:

    private class MyWebViewClient extends WebViewClient {
        public void onPageFinished(WebView view, String url) {
            view.setInitialScale((int)(100*view.getScale()));
        }
    }
    

    then just set this as your WebView's client:

    webview.setWebViewClient(new MyWebViewClient());
    
    0 讨论(0)
  • 2020-11-30 02:50

    Zooming of WebView can be controlled programatically by zoomIn() and zoomOut() methods

    0 讨论(0)
  • 2020-11-30 02:58

    try this thing

    int default_zoom_level=100;
    Point Scroll=new Point(0,0);
    webview1.setInitialScale(default_zoom_level);
        webview1.loadData("url");
    

    After doing zoomIn/ZoomOut or Scrolling.Since Scale may be get to change so calculate scale level and scrolling along X and Y Axis.

    int current_scale_level=(int)webview1.getScale()*100;
    Scroll.x=webview1.getScrollX();
    Scroll.y=webview1.getScrollY();
    
    then before loading of next webview do this
    
    webview2.setInitialScale(current_scale_level);
        webview2.loadData("url");
    webview2.scrollTo(Scroll.x,Scroll.y);
    
    0 讨论(0)
  • 2020-11-30 03:00

    Before you leave the first page, use

    int scale = 100 * webView.getScale();
    

    Then after you load the second page, use

    webView.setInitialScale( scale );
    
    0 讨论(0)
  • 2020-11-30 03:02

    use the webSettings class

    webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    

    Notice that although webSettings is available since API Level 1, WebSettings.ZoomDensity is available since API Level 7. Works well for all device resolutions.

    Also, in order to enable zoom on the webView, add the following code:

    webView.getSettings().setBuiltInZoomControls(true);
    
    0 讨论(0)
提交回复
热议问题