计算的android屏幕尺寸? [英] Calculating android screen size?
本文介绍了计算的android屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能来计算英寸Android的屏幕对角线尺寸。
Is it possible to calculate the android screen diagonal dimension in inches.
我曾尝试以下两种方法无论是不适合我的情况。
I have tried below two approaches both is not suitable for my case.
方法一:
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;
方法2:
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));
你能不能改正,如果我错了。
Could you correct if i am wrong.
谢谢, Easwar
Thanks, Easwar
推荐答案
我在8 Android设备测试,我的两个方法。第二个是几乎准确。
I have tested both of my approach in 8 android devices. The second is almost accurate.
但对于一些设备,这是不给予适当的回答。所以,我的结论如下第二种方法。
But for few devices this is not giving proper answer. So I concluded following the second approach.
这篇关于计算的android屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文