+-
如果我在布局上有某个视图(例如 ImageView),是否可以找到从视图底部边框到手机屏幕底部的距离?
谢谢.
最佳答案
// instantiate DisplayMetrics
DisplayMetrics dm = new DisplayMetrics();
// fill dm with data from current display
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
// loc will hold the coordinates of your view
int[] loc = new int[2];
// fill loc with the coordinates of your view (loc[0] = x, looc[1] = y)
yourImageView.getLocationOnScreen(loc);
// calculate the distance from the TOP(its y-coordinate) of your view to the bottom of the screen
int distance = dm.heightPixels - loc[1];
点击查看更多相关文章
转载注明原文:android – 如何从View到手机底部的距离? - 乐贴网