如何准确计算android中三星Galaxy Edge的屏幕尺寸
如何在考虑边缘部分的情况下准确计算屏幕尺寸? 现在,我正在开发自定义键盘,当它变得可见时,它的大小将根据屏幕大小以编程方式计算 我使用的计算屏幕大小的函数如下所示如何准确计算android中三星Galaxy Edge的屏幕尺寸,android,keyboard,resolution,dimension,Android,Keyboard,Resolution,Dimension,如何在考虑边缘部分的情况下准确计算屏幕尺寸? 现在,我正在开发自定义键盘,当它变得可见时,它的大小将根据屏幕大小以编程方式计算 我使用的计算屏幕大小的函数如下所示 public static Point getDimentionalSize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display =
public static Point getDimentionalSize(Context context)
{
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int realWidth;
int realHeight;
if (Build.VERSION.SDK_INT >= 17){
//new pleasant way to get real metrics
DisplayMetrics realMetrics = new DisplayMetrics();
display.getRealMetrics(realMetrics);
realWidth = realMetrics.widthPixels;
realHeight = realMetrics.heightPixels;
} else if (Build.VERSION.SDK_INT >= 14) {
//reflection for this weird in-between time
try {
Method mGetRawH = Display.class.getMethod("getRawHeight");
Method mGetRawW = Display.class.getMethod("getRawWidth");
realWidth = (Integer) mGetRawW.invoke(display);
realHeight = (Integer) mGetRawH.invoke(display);
} catch (Exception e) {
//this may not be 100% accurate, but it's all we've got
realWidth = display.getWidth();
realHeight = display.getHeight();
Log.e("Display Info", "Couldn't use reflection to get the real display metrics.");
}
} else {
//This should be close, as lower API devices should not have window navigation bars
realWidth = display.getWidth();
realHeight = display.getHeight();
}
return new Point(realWidth, realHeight);
}
此函数以像素为单位精确计算屏幕大小。
但当我在三星Galaxy Note Edge上试用时,屏幕宽度也构成了设备的边缘部分。
我想从屏幕大小中排除它。(如果是纵向,则从宽度,否则从高度)
解决方案是什么?你可以试试这个
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
谢谢你的快速回复。我试过了,但也没用。