我们可以使用 DisplayMetrics 获取设备的屏幕高度,然后计算出所需要的 Y 坐标值。以下是代码示例:
int screenHeight = getResources().getDisplayMetrics().heightPixels;
int bottomFiveY = screenHeight - 5;
// 要获取某个 View 的底部 5 个像素时,可以用以下代码
View view = findViewById(R.id.view);
int[] location = new int[2];
view.getLocationOnScreen(location);
int bottomFiveViewY = location[1] + view.getHeight() - 5;
这样,我们就可以轻松地获取屏幕底部 5 个像素的 Y 坐标了,或者获取某个 View 的底部 5 个像素的 Y 坐标。