Incorrect Coordinates From getLocationOnScreen/getLocationInWindow

前端 未结 4 1295
时光取名叫无心
时光取名叫无心 2020-11-29 02:10

A call to getLocationOnScreen() or getLocationInWindow() both give me a top/Y coordinate that is about ~30px (status/notifications bar

4条回答
  •  执笔经年
    2020-11-29 02:14

    I am having the same problem, try using

    offset = myView.GetOffsetY();
    

    and adjust your Y coord by that value, e.g.

    coordY -= offset;
    

    The class which offers the ``-method:

    class MyView extends View {
    
      public int GetOffsetY() {
        int mOffset[] = new int[2];
        getLocationOnScreen( mOffset );
        return mOffset[1]; 
      }
    
    }
    

提交回复
热议问题