Adaptive webview screen in Android

Source: Internet
Author: User

Can the zoom button in the lower right corner of webview be removed?

Settings. setdisplayzoomcontrols (false );// Hide the webview zoom button

 

There are several methods I know to center the page loaded by webview

Method 1:

Websettings settings = webview. getsettings ();
Settings. setlayoutalgorithm (layoutalgorithm.Single_column);
Layoutalgorithm is an enumeration used to control the page layout. There are three types:

1. narrow_columns: if possible, the width of all columns should not exceed the screen width.

2. Normal: normal display without any Rendering

3. single_column: enlarge all content in a column with the same width as webview.

The single_column type can be used to set the center display of the page, and the page can be zoomed in and out, but this method is not very good. Sometimes it will make your page layout look like it. I tested it and can only display the middle part, any part that exceeds the screen cannot be displayed.

 

Method 2:

// Set the adaptive mobile phone screen for the loaded page
Settings. setusewideviewport (true );
Settings. setloadwithoverviewmode (true );
The first method sets the window recommended for webview to true. The second method is to set the page loading mode of webview, and also to true.

This method allows your page to adapt to the resolution of the mobile phone screen. It is completely displayed on the screen and can be zoomed in or out.

Both methods have been tried. The second method is recommended.

 

Method 3(Mainly used for flat panel to adjust the resolution for specific screen code)
Displaymetrics metrics = new displaymetrics ();
Getwindowmanager (). getdefaultdisplay (). getmetrics (metrics );
Int mdensity = metrics. densitydpi;

If (mdensity = 120 ){
Settings. setdefazoom zoom (zoomdensity. Close );
} Else if (mdensity = 160 ){
Settings. setdefazoom zoom (zoomdensity. Medium );
} Else if (mdensity = 240 ){
Settings. setdefazoom zoom (zoomdensity. Far );
}

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.