gpt4 book ai didi

android - getRight、getLeft、getTop 返回零

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:06 27 4
gpt4 key购买 nike

我正在使用以下代码。但是所有方法都返回零值。我知道要获得 View 的坐标,我们的 View 应该被绘制。这就是为什么我在 onResume 方法中使用代码但仍然无法正常工作的原因。有什么想法吗?

 @Override
public void onResume(){
super.onResume();
System.out.println("Onresume");
System.out.println("tab1 - left" + btn_Tab7 .getLeft());
System.out.println("tab1 - Top" + btn_Tab7.getTop());
System.out.println("tab1 - right" + btn_Tab7.getRight());
System.out.println("tab1 - bottom" + btn_Tab7.getBottom());
}

最佳答案

onResume 中调用 getLeft、getRight 还为时过早...在 onWindowFocusChanged

中执行
@Override
public void onWindowFocusChanged (boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
System.out.println("onWindowFocusChanged");
System.out.println("tab1 - left" + btn_Tab7 .getLeft());
System.out.println("tab1 - Top" + btn_Tab7.getTop());
System.out.println("tab1 - right" + btn_Tab7.getRight());
System.out.println("tab1 - bottom" + btn_Tab7.getBottom());
}
}

来自 onResume 的文档:

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).

关于android - getRight、getLeft、getTop 返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052570/

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