Fitting webpage contents inside a webview (Android)

前端 未结 2 1814
说谎
说谎 2020-12-13 04:17

Simple question.

I\'m trying to stretch the contents of a webview so that the entire webpage within is visible. i.e no scrolling. I\'ve looked through the docs but c

相关标签:
2条回答
  • 2020-12-13 05:10

    I've tried all methods above but in my case nothing worked until I found out:

       <meta name="viewport" content="user-scalable=no"/>
    

    remove this line in the html file or simply change user-scalable=yes, and everything will be fine. Took me almost one day to find out this crazy line.

    0 讨论(0)
  • 2020-12-13 05:12

    So People can use this as a tutorial in the future.

    There are a bunch of ways to handle zooms in android and fitting pages. It can be pretty temperamental at times and some methods work better than others.

    For most people, Just use this:

    WebView x;
    
    x.setInitialScale(1);
    

    This is the furtheset zoom possible. But for some sites it just looks pure UGLY.

    This was the second version I found

    test1.getSettings().setDefaultZoom(ZoomDensity.FAR);
    

    Thats a nice all rounder than seems to just zoom out far enough for a lot but still not what I was looking for.

    And now heres the final solution I have.

    x.getSettings().setLoadWithOverviewMode(true);
    x.getSettings().setUseWideViewPort(true);
    

    Basically what these do is answered in another question like this.

     setLoadWithOverviewMode(true) 
    

    Loads the WebView completely zoomed out

    setUseWideViewPort(true)
    

    Makes the Webview have a normal viewport (such as a normal desktop browser), while when false the webview will have a viewport constrained to it's own dimensions (so if the webview is 50px*50px the viewport will be the same size)

    0 讨论(0)
提交回复
热议问题