gpt4 book ai didi

android - 为什么屏幕上的位置总是返回 0?

转载 作者:行者123 更新时间:2023-11-30 00:48:11 25 4
gpt4 key购买 nike

我想知道 ImageView 的位置,但它总是返回 0 x 坐标或 y 坐标。这是我的代码

    ImageView credits = (ImageView) v.findViewById(R.id.credits);
int[] coor = {0,0};
credits.getLocationOnScreen(coor);
x = coor[0];
y = coor[1];

我已经使用了很多方法,例如getTop()等,但它仍然返回0。

有人知道为什么吗?我是 android 的新手,所以我非常感谢任何答案。

最佳答案

您是在 onCreate 方法中这样做吗?

如果是,那么在 onCreate() 中检查 getLocationOnScreen() 还为时过早

此处的解决方案:https://stackoverflow.com/a/13244091/5392383

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

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