Methods to get position of view returns 0

ε祈祈猫儿з 提交于 2019-12-04 03:18:25

You put the 'measuring' in the onWindowFocusChanged()-method.
As the documentation states:

This is the best indicator of whether this activity is visible to the user.

You could also put it in the onResume() which is the last step before the application is completely on screen and active, however:

Keep in mind that onResume is not the best indicator that your activity is visible to the user; a system window such as the keyguard may be in front. Use onWindowFocusChanged(boolean) to know for certain that your activity is visible to the user (for example, to resume a game).

If the window/view has not yet been displayed there is no guarantee that it has its measurements, thus the previous method would be better.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!