GetRight时,getLeft,共达回零GetRight、getLeft、共达回零

2023-09-06 09:43:33 作者:伤↑

我使用下面的code。但所有的方法都返回零值。我知道,得到的观点我们认为应绘制的坐标。这就是为什么我现在用的是code在onResume方法,但仍无法正常工作。你知道吗?

  @覆盖
公共无效onResume(){
    super.onResume();
    的System.out.println(Onresume);
    的System.out.println(TAB1  - 左边的+ btn_Tab7 .getLeft());
    的System.out.println(TAB1  - 顶+ btn_Tab7.getTop());
    的System.out.println(TAB1  - 右+ btn_Tab7.getRight());
    的System.out.println(TAB1  - 底+ btn_Tab7.getBottom());
}
 

解决方案

onResume 其为时尚早getLeft,GetRight时... 做到这一点的 onWindowFocusChanged

  @覆盖
公共无效onWindowFocusChanged(布尔hasFocus){
    super.onWindowFocusChanged(hasFocus);
    如果(hasFocus){
        的System.out.println(onWindowFocusChanged);
        的System.out.println(TAB1  - 左边的+ btn_Tab7 .getLeft());
        的System.out.println(TAB1  - 顶+ btn_Tab7.getTop());
        的System.out.println(TAB1  - 右+ btn_Tab7.getRight());
        的System.out.println(TAB1  - 底+ btn_Tab7.getBottom());
    }
}
 
I m sorry I can t get on the bus because I my ticket in the office just now.A.left B.forgot C.have left D.have forgotten 题目和参考答案

从onResume文档:

  

请注意, onResume是不是最好的指标,你的   活动是用户可见;一个系统窗口,如键盘锁   可能是在前面。使用onWindowFocusChanged(布尔)肯定知道   您的活动是用户可见的(例如,恢复一个   游戏)。

I am using following code. But all methods are returning zero value. I know that to get the coordinates of the view our view should be drawn. That why i am using the code in onResume method but still not working. Any Idea?

 @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()); 
}

解决方案

in onResume its too early to call getLeft, getRight ... Do it in 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());
    }
}

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

相关推荐