android - getLocationOnScreen 返回的位置是什么?

标签 android

据我所知,当我们将 int[2] 位置数组传递给 view.getLocationOnScreen(location) 时,我们将获得该 View 的左上角坐标。但是当我调试这个函数时,我看到那个位置返回那个 View 的右上角坐标。我的屏幕是 480x800,我的 View margin right 是 40,所以 View 的右坐标是 440 ,它等于 location[0] 从 view.getLocationOnScreen(location) 返回。为什么 location[0] 返回右 View 坐标?

最佳答案

它是该 View 左上角坐标的精确返回值。我得到了错误的值,因为在调用 view.getLocationOnScreen(location) 之前我的 View 仍未呈现。

关于android - getLocationOnScreen 返回的位置是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11776867/

相关文章:

android - API 'variant.getExternalNativeBuildTasks()' 已过时并已替换为 'variant.getExternalNativeBuildProviders()

android - Cocoa 异步套接字 java 实现

android - API/数据源 - 链接和按使用付费

android - 使用红外线检测 ios 或 android 设备中的对象

安卓 : WebView onPageFinished not calling after shouldOverrideUrlLoading method in android 4. 4

android - 无法混合音频和视频

android - 设置折叠工具栏中 TextView 和 ImageView 的对比度颜色

android - Integer.parseInt 抛出 NumberFormatException?

java - 尝试在空对象引用上调用虚拟方法 'android.content.Context android.content.Context.getApplicationContext()'

android - 获取客户端的 IP 地址或获取连接到 Hotspot Android 的客户端的信息(SSID)(Tethering 后)