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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With