Listen to the view if the view changes its position XY

How can I listen to a view to get XY coordination if it moves or its XY changes? Viewing is not required to be dragged (or by a custom touch event), it can change if the orientation is changed or pressed (up) using the display keyboard, etc. I want to know her updated XY coordination when she changes, how can I do this?

+4
source share
1 answer

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.

+7
source

All Articles