getLocationOnScreen学习笔记
百度看到的解释
获取View相对屏幕(整个屏幕包括statusBar)左上角的坐标
验证
-
获取状态栏statusBar的高度
Rect rect = new Rect(); getWindow.getDecorView.getWindowVisibleDisplayFrame(rect); int statusBar = rect.top;
-
获取标题栏actionBar的高度
int[] attributes = {android.R.attr.actionBarSize}; TypedArray typedArray = context.obtainStyledAttributes(attributes); float actionBarSize = typedArray.getDeminsion(0,0); typedArray.recycle();
-
获取View的getLocationOnScreen值
int locations = new int[2]; view.getLocationOnScreen(locations); int x = locations[0]; int y = locations[1];
-
在测试手机运行,得出y == statusBar + actionBar,所以,上面的解释正确。