把写内容过程常用的内容片段做个备份,下边内容内容是关于Android中获取屏幕尺寸的的内容,应该能对各位朋友有用。
public static String getDisplayMetrics(Context cx) {
String str = "";
DisplayMetrics dm = new DisplayMetrics();
dm = cx.getApplicationContext().getResources().getDisplayMetrics();
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) + "pixelsn";
str += "The absolute heightin:" + String.valueOf(screenHeight)
+ "pixelsn";
str += "The logical density of the display.:" + String.valueOf(density)
+ "n";
str += "X dimension :" + String.valueOf(xdpi) + "pixels per inchn";
str += "Y dimension :" + String.valueOf(ydpi) + "pixels per inchn";
return str;
}
网友评论