一般通用webview设置支持缩放
public voidsetWebViewSetting() {
//设置自适应屏幕
WebSettings settings =previewWebview.getSettings();
DisplayMetrics metrics =newDisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
intmDensity = metrics.densityDpi;
if(mDensity ==120) {
settings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
}else if(mDensity ==160) {
settings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
}else if(mDensity ==240) {
settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
}
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
settings.setJavaScriptEnabled(true);
previewWebview.setWebViewClient(newWebViewClient() {
@Override
public voidonPageStarted(WebView view,String url,Bitmap favicon) {
super.onPageStarted(view,url,favicon);
}
@Override
public voidonPageFinished(WebView view,String url) {
super.onPageFinished(view,url);
}
});
}
webview的设置属性
setJavaScriptEnabled(true);//支持js
setPluginsEnabled(true);//支持插件
setUseWideViewPort(false);//将图片调整到适合webview的大小
setSupportZoom(true);//支持缩放
setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);//支持内容重新布局
supportMultipleWindows();//多窗口
setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//关闭webview中缓存
setAllowFileAccess(true);//设置可以访问文件
setNeedInitialFocus(true); //当webview调用requestFocus时为webview设置节点
webview webSettings.setBuiltInZoomControls(true);//设置支持缩放
setJavaScriptCanOpenWindowsAutomatically(true);//支持通过JS打开新窗口
setLoadWithOverviewMode(true); // 缩放至屏幕的大小
setLoadsImagesAutomatically(true);//支持自动加载图片