Reproduced WebView Adaptive screen in Android

Source: Internet
Author: User

WebView in the lower right corner of the zoom button can not be removed

Settings.setdisplayzoomcontrols (false); Hide WebView Zoom button

let WebView load the page center display there are several ways I know

The first method:

WebSettings settings = Webview.getsettings ();
Settings.setlayoutalgorithm (layoutalgorithm. Single_column);
Layoutalgorithm is an enumeration used to control the layout of a page, with three types:

1.narrow_columns: If possible, the width of all columns does not exceed the screen width

2.NORMAL: Normal display does not make any rendering

3.single_column: Enlarge All content in a column webview equal width

With the Single_column type can set the page center display, the page can zoom in and out, but this method is not good, and sometimes make your page layout is out of shape and I measured, can only show the middle piece, beyond the screen can not be displayed.

The second method:

Set up the loaded page Adaptive phone screen
Settings.setusewideviewport (true);
Settings.setloadwithoverviewmode (TRUE);
The first method sets the WebView recommended window, set to True. The second method is to set the mode for WebView loaded pages and also set to true.

This method can make your page adapt to the resolution of the phone screen, complete display on the screen, you can zoom in and zoom out.

Both methods have been tried, the second method is recommended

Third method : (mainly for tablets, adjust the resolution for specific screen code)
Displaymetrics metrics = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (metrics);
int mdensity = metrics.densitydpi;


if (mdensity = = 120) {
Settings.setdefaultzoom (Zoomdensity.close);
}else if (mdensity = = 160) {
Settings.setdefaultzoom (Zoomdensity.medium);
}else if (mdensity = = 240) {
Settings.setdefaultzoom (Zoomdensity.far);
}

Blog Original: http://www.cnblogs.com/bluestorm/archive/2013/04/15/3021996.html

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.