Android坐标原点为左上角,如果是某个View,那么就以该矩阵的左上角为原点

1、绝对坐标 Location

int[] location = new  int[2] ;
view.getLocationInWindow(location); //获取在当前窗口内的绝对坐标,含toolBar
view.getLocationOnScreen(location); //获取在整个屏幕内的绝对坐标,含statusBar
// location [0]--->x坐标,location [1]--->y坐标
// 需要在UI控件都加载完成才能正确获取。例如在onWindowFocusChanged(boolean hasFocus)回调中获取。

2、通过LayoutParams 获取位置,需要注意的是,params.y是在窗口内的绝对坐标,不含statusBar

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.x= x;
lp.y= y;

3、获取相对在它父亲里的坐标

  View.getLeft(), getTop(), getBottom(), getRight()

4、获取屏幕高度、标题高度、状态栏高度详解

5、点击坐标比较详细的文章

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-12-02
  • 2022-02-01
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
相关资源
相似解决方案