Finding the View location (position) on display (screen) in android

后端 未结 5 451
滥情空心
滥情空心 2020-12-19 04:50

I want to find the view\'s position on the display screen.

To do it, I use the methods such as view.getLeft() ,view.getBottom() , vi

5条回答
  •  天涯浪人
    2020-12-19 04:57

    the methods u have written is enough to find the location on screen, but the place where you have written is not correct.

    try to write the methods (view.getLeft(), view.getTop()... etc) in onWindowFocusChanged(boolean hasFocus) method.

    for example...

    **

    @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            if (hasFocus) {
                    System.out.println("Right:"+tv2.getRight());
                    System.out.println("Left:"+tv2.getLeft());
                    System.out.println("Top:"+tv2.getTop());
            }
        }
    

    **

    it will solve your issue.

提交回复
热议问题