FrankSu
FrankSu

Reputation: 331

why is onPreDraw() called twice?

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

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

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!

Upvotes: 4

Views: 1194

Answers (1)

Teng-pao Yu
Teng-pao Yu

Reputation: 1443

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

Upvotes: 2

Related Questions