How do I listen on a View to obtain its XY coordination if it is moving or its XY position change? The View is not necessary to be dragged (or by user touch event), it may change if the orientation change or pushed (upward) by the showing keyboard or etc. I want to know its updated XY coordination when it changes, how can I do that?
You may do something like this
final View activityRootView = findViewById(R.id.mainLayout);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
findViewById(R.id.textView).getX();
findViewById(R.id.textView).getY();
}
});
Hope this helps.
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