gpt4 book ai didi

Android:如何获取 View 的坐标(不包括Actionbar)

转载 作者:行者123 更新时间:2023-11-29 01:25:57 24 4
gpt4 key购买 nike

使用View.getLocationOnScreen()可以得到坐标,但是比我想象的要大一点,所以我觉得我得到的坐标是相对于全屏的(包括 Action 条) 。有没有什么方法可以在不包含 ActionBar 的情况下获取坐标?请参见下图。

I want the green 'y',not the yellow one

最佳答案

请先看这张图:

enter image description here

这个链接告诉你如何获取按钮的当前位置(图片中的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com