为什么 onPreDraw() 被调用两次? [英] why is onPreDraw() called twice?

查看:84
本文介绍了为什么 onPreDraw() 被调用两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 textView.getTop() 方法但只得到 0.我使用 onPreDraw() 方法作为 kcoppock这个问题中说.

I was trying to use textView.getTop() method but getting only 0. And I used the onPreDraw() method as kcoppock said in this question.

但是,在我的情况下 onPreDraw() 方法被调用了两次.

However, the onPreDraw() method was called twice in my situation.

我可以解决这个问题,但我只想知道 onPreDraw() 方法何时被准确调用.谷歌的文档说它在视图树即将被绘制时被调用.这究竟是什么意思?

I can handle that but I just want to know when is the onPreDraw() method called exactly. The google's documentation says it's invoked when the view tree is about to be drawn. What's that actually mean?

有哪位朋友能告诉我或告诉我在哪里可以找到答案吗?谢谢!

Could any buddy tell me or show me where to find the answer? Thx!

推荐答案

监听器会报告所有 onPreDraw() 直到你 删除监听器.如果您只想接收一个 onPreDraw() 报告,请尝试新的 androidx OneShotPreDrawListener

The listener will report all onPreDraw() until you remove the listener. If you only want to receive one onPreDraw() report, try the new androidx OneShotPreDrawListener

这篇关于为什么 onPreDraw() 被调用两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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