获取手机DPI

        在有些做手机适配方案的时候,需要得知手机dpi,可采用以下代码:



private void printDPI() {
	 String str = "";
	 DisplayMetrics dm = new DisplayMetrics();
	 // getWindowManager().getDefaultDisplay().getMetrics(dm);
	 dm = this.getApplicationContext().getResources().getDisplayMetrics();
	 int screenWidth = dm.widthPixels;
	 int screenHeight = dm.heightPixels;
	 float density = dm.density;
	 float dpi = dm.densityDpi;
	 float widthPixels = dm.widthPixels;
	 float xdpi = dm.xdpi;
	 float ydpi = dm.ydpi;
	
	 str += "屏幕分辨率为:" + dm.widthPixels + " * " + dm.heightPixels + "\n";
	 str += "绝对宽度:" + String.valueOf(screenWidth) + "pixels\n";
	 str += "绝对高度:" + String.valueOf(screenHeight) + "pixels\n";
	 str += "逻辑密度:" + String.valueOf(density) + "\n";
	 str += "dpi:" + String.valueOf(dpi) + "\n";
	 str += "widthPixels:" + String.valueOf(widthPixels) + "\n";
	 str += "X 维 :" + String.valueOf(xdpi) + "像素每英尺\n";
	 str += "Y 维 :" + String.valueOf(ydpi) + "像素每英尺\n";
	
	 Log.i("@@@@@@", str);
	 }


获取手机DPI,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。