What triggers a View's measure() to be called

前端 未结 2 1207
独厮守ぢ
独厮守ぢ 2021-02-05 00:13

In my application I have an infinite loop on one of my View\'s onMeasure() overrides. Debugging the source code starting from a break point in my onMeasure, I am able to trace

2条回答
  •  有刺的猬
    2021-02-05 00:40

    Well, If you are changing a View's content, it will eventually have to call invalidate(). For example, you have a TextView with a text called "Text 1". Now, you change the text of the same TextView to "Text 2". Here aslo, invalidate will be called.

    So basically, when something changes on the view, more often than not, you would expect the invalidate method to be called, and a corresponding call to the measure().

    Look at the source code for TextView, for example. http://www.google.com/codesearch#uX1GffpyOZk/core/java/android/widget/TextView.java&q=TextView%20package:android&type=cs

    Count the number of invalidate calls. There are quite a few.

提交回复
热议问题