本文介绍了GetRight时,getLeft,共达回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的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());
    }
}
 

从onResume文档:

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:

这篇关于GetRight时,getLeft,共达回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:39