You can 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.
source
share