首页 > 移动平台 > 详细

获取手机DPI

时间:2014-04-02 08:21:11      阅读:523      评论:0      收藏:0      [点我收藏+]

        在有些做手机适配方案的时候,需要得知手机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,布布扣,bubuko.com

获取手机DPI

原文:http://blog.csdn.net/lilu_leo/article/details/22722629

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!