如果视图更改其XY位置,请在视图上侦听 [英] Listen on a View if the View change its XY position

查看:67
本文介绍了如果视图更改其XY位置,请在视图上侦听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果视图正在移动或XY位置发生变化,如何在视图上侦听以获取其XY坐标?视图不一定要拖动(或通过用户触摸事件),如果方向发生变化或显示键盘或其他方向(向上)将其推(向上),则视图可能会发生变化.我想知道其更改后的更新后的XY坐标,我该怎么办?这样做吗?

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?

推荐答案

您可以这样做

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();

                    }
                });

希望这会有所帮助.

这篇关于如果视图更改其XY位置,请在视图上侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆