利用DisplayMetrics获取屏幕信息
2013-11-19 19:45
423 查看
public static String getDisplayMetrics(Context cx) {
String str = "";
DisplayMetrics dm = new DisplayMetrics();
//取得DisplayMetrics对象方法一
//dm = cx.getApplicationContext().getResources().getDisplayMetrics();
//取得DisplayMetrics对象方法二
((Activity)cx).getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
float density = dm.density;
float xdpi = dm.xdpi;
float ydpi = dm.ydpi;
str += "The absolute width:" + String.valueOf(screenWidth) + "pixels\n";
str += "The absolute heightin:" + String.valueOf(screenHeight) + "pixels\n";
str += "The logical density of the display.:" + String.valueOf(density)
+ "\n";
str += "X dimension :" + String.valueOf(xdpi) + "pixels per inch\n";
str += "Y dimension :" + String.valueOf(ydpi) + "pixels per inch\n";
return str;
}
String str = "";
DisplayMetrics dm = new DisplayMetrics();
//取得DisplayMetrics对象方法一
//dm = cx.getApplicationContext().getResources().getDisplayMetrics();
//取得DisplayMetrics对象方法二
((Activity)cx).getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
float density = dm.density;
float xdpi = dm.xdpi;
float ydpi = dm.ydpi;
str += "The absolute width:" + String.valueOf(screenWidth) + "pixels\n";
str += "The absolute heightin:" + String.valueOf(screenHeight) + "pixels\n";
str += "The logical density of the display.:" + String.valueOf(density)
+ "\n";
str += "X dimension :" + String.valueOf(xdpi) + "pixels per inch\n";
str += "Y dimension :" + String.valueOf(ydpi) + "pixels per inch\n";
return str;
}
相关文章推荐
- Java基础重温(十二)-scjp 4
- iOS7 UI改变总结
- Is it a bug in MySQL or in java-connector?——转
- 各种手机的SD卡
- [css layout][15]Liquid, secondary columns fixed-width
- Cisco 路由器启动过程详解及重置密码的原理
- Android签名
- Red Hat 6.2中chattr命令的使用方法
- VIM6:linux终端下的英文字典--SDCV
- Arrays工具类十大常用方法
- Arrays工具类十大常用方法
- Arrays工具类十大常用方法
- 构造器与多态
- SQLite的事务管理
- Ogre:Animation(Ogre中的动画)
- openstack-db命令初始化数据库出错,解决方法!
- hibernate 分页查询
- blog的事儿
- Xcode中 xx duplicate symbols for architecture i386错误提示
- 中文报错newline in constant