Android 4.1 WebView 页面整体缩放

丫的以前在2.3上做的AP,使用的是setZoom,前两天在手机4.2上run的时候也没发现啥问题

	public void screenSetting()
    {
		int screenDensity = getResources().getDisplayMetrics().densityDpi ;   
		WebSettings.ZoomDensity zoomDensity = WebSettings.ZoomDensity.MEDIUM ;
		switch (screenDensity){   

		case DisplayMetrics.DENSITY_LOW :
		    zoomDensity = WebSettings.ZoomDensity.CLOSE;
		    break;   

		case DisplayMetrics.DENSITY_MEDIUM:   
		    zoomDensity = WebSettings.ZoomDensity.CLOSE;   
		    break;   

		case DisplayMetrics.DENSITY_HIGH:   
		    zoomDensity = WebSettings.ZoomDensity.FAR;   
		    break ;   
		}
		webview.getSettings().setDefaultZoom(zoomDensity);//webSettings.setDefaultZoom(zoomDensity);		
    }



偶然在4.1的8寸平板上跑,发现字体出奇的小,查了dpi没有问题,函数也正常,界面大小死活不变,后来查了半天,有人说这个设置在4.1以上无效了(因为4.0我试了也正常),有人说是机器的问题,不管啥问题,反正是用不成了,后来只能通过字体缩放来搞定了,因为之前webview里面有图片,所以需要整体缩放,现在单纯的缩放字体也不是很合适,考虑用css来调整图片大小吧~~Android的碎片伤不起呀。。。。

    		int screenDensity = context.getResources().getDisplayMetrics().densityDpi ;
    		switch (screenDensity){
    		case DisplayMetrics.DENSITY_LOW:
    			DEFAULTFONTSIZE = 20;
    		    break;

    		case DisplayMetrics.DENSITY_MEDIUM:
    			DEFAULTFONTSIZE = 20;
    		    break;   

    		case DisplayMetrics.DENSITY_HIGH:
    		    DEFAULTFONTSIZE = 16;
    		    break ;  
    		    
    		case DisplayMetrics.DENSITY_XHIGH:
    		    DEFAULTFONTSIZE = 16;
    		    break ; 
    		}   
    		webview.getSettings().setDefaultFontSize(DEFAULTFONTSIZE);
    		



猜你喜欢

转载自will-du.iteye.com/blog/1775709