使用View.getLocationOnScreen()
可以得到坐标,但是比我想象的要大一点,所以我觉得我得到的坐标是相对于全屏的(包括 Action 条
) 。
有没有什么方法可以在不包含 ActionBar
的情况下获取坐标?
请参见下图。
最佳答案
请先看这张图:
这个链接告诉你如何获取按钮的当前位置(图片中的110)
How to get the absolute coordinates of a view
第二个链接计算Actionbar高度(图中72)
How to get the ActionBar height?
最后一个链接告诉你如何计算Statusbar(图中38)
Height of status bar in Android
现在你可以用这个等于(110 = 72 + 38)得到当前位置
希望能帮到你。
关于Android:如何获取 View 的坐标(不包括Actionbar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34065789/