Reputation: 6569
I need to get current coordinate of edittext on screen. I am using OnGlobalLayoutListener
but it is called two times instead of one time and another disadvantage that it called too late.
If any way how to get position of editText immediately when it was created?
Upvotes: 0
Views: 1469
Reputation: 12717
Use View.getLocationOnScreen() and/or getLocationInWindow(). You can use in onWindowFocusChanged
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
int[] locationInWindow = new int[2];
object.getLocationInWindow(locationInWindow);
Log.v("TAG","getLocationInWindow() - "+ locationInWindow[0] + " : " + locationInWindow[1]);
}
Upvotes: 2