Android WebView (ii) zoom

Source: Internet
Author: User

Many times a page that requires webview loading can be scaled to make it easier to read.
In fact, WebView scale is not so simple, can not be set by one or two properties, generally need to set a few properties at the same time:
Settings can support scaling websettings.setsupportzoom (true); The Zoom tool Websettings.setbuiltinzoomcontrols (TRUE) is set, and//settings can be dragged up or down in the wide field of view, and can be scaled arbitrarily websettings.setusewideviewport (true);//Set the visual range of the default load is the large field of view Websettings.setloadwithoverviewmode (TRUE);//Adaptive Screen Websettings.setlayoutalgorithm ( Layoutalgorithm.single_column);
SetsupportzoomMust be set, but only setting this property does not scale, and on some versions of the phone it is only possible to achieve click Scaling.
SetbuiltinzoomcontrolsSetting this property visually implements two phone slide scaling and displays a zoom tool on the screen.
SetusewideviewportThis property actually needs to be set according to the page you want to load, because some pages are very early only for the PC browser page, the page is large, need a wide view to show, this time set to true can be in enough space to drag, and the page can be scaled at any scale.
SetloadwithoverviewmodeThis property is true to show the page in the largest possible field of view, which is used in conjunction with the previous attribute. Of course, the big view of the words are very small.
SetlayoutalgorithmIn fact, this property is not recommended, but also a property that Google gave up. This property is used to control the layout of the page, with three types:
Single_column: Zoom in on all content to a column of webview width.
Normal: No rendering is displayed normally.
Narrow_columns: If possible, let the width of all columns not exceed the width of the screen.


If your webpage doesn't want to zoom, and you want the page to be adaptive to your phone's screen, you can add the following attribute to your HTML file:
<meta name= "viewport" content= "Width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" >    <meta name= "mobileoptimized" content= "width" >    <meta name= "handheldfriendly" content= "true" >

WebView when loading a page containing the above properties, even if the webview is set to scale, the page will not be scaled, and the page can be as

The right way to show it. In fact this is to do page popular is also recommended practice.



Android WebView (ii) zoom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.