计算从视图到屏幕底部的像素

Calculate Pixels from View to bottom of screen

我有一个带有 Spinner 的布局:

我想获取从微调器顶部到屏幕底部的像素数。有办法实现吗?

要计算距视图顶部的距离,首先 find the distance of view from bottom 并添加视图高度

DisplayMetrics dm = new DisplayMetrics(); 
           getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int[] loc = new int[2];
yourView.getLocationOnScreen(loc);
int distance = dm.heightPixels - loc[1];
Int viewHeight = yourView.getHeight()
distance +=viewHeight; //distance from top of the view