是否可以以英寸为单位计算 android 屏幕对角线尺寸。
我尝试了以下两种方法,都不适合我的情况。
方法一:
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int absoluteHeightInPx = displayMetrics.heightPixels;
int absoluteWidthInPx = displayMetrics.widthPixels;
double diagonalPixels = Math.sqrt((absoluteHeightInPx * absoluteHeightInPx) + (absoluteWidthInPx * absoluteWidthInPx));
double diagonalInInches = diagonalPixels / displayMetrics.densityDpi;
方法二:
float actualHeight = absoluteHeightInPx * deviceDensity;
float actualWidth = absoluteWidthInPx * deviceDensity;
float deviceDensity = displayMetrics.density;
float physicalPixelPerInchX = displayMetrics.xdpi;
float physicalPixelPerInchY = displayMetrics.ydpi;
float heightInInches = actualHeight / physicalPixelPerInchY;
float widhtInInches = actualWidth / physicalPixelPerInchX;
double diagonalInInches = Math.sqrt((heightInInches * heightInInches) + (widhtInInches * widhtInInches));
如果我错了,你能纠正吗?
谢谢,伊斯瓦尔