Why is requestLayout being called directly after invalidate

后端 未结 4 877
庸人自扰
庸人自扰 2020-12-09 18:27

I\'m learning about custom views and wanted to learn about invalidate() and requestLayout().

Please refer to this answer and its diagram:

4条回答
  •  猫巷女王i
    2020-12-09 19:10

    Relevant excerpt from the book Expert Android that answers the question:

    Because the onClick event has caused the dimensions to change, our view needs to become bigger and take more space. How do we express that need to Android, Well, we request Layout(). This method goes up the chain, marking every view parent that it needs to be remeasured. When the final parent gets this request (the view root), the parent schedules a layout traversal. A layout traversal may or may not result in onDraw, although in this case it should. As a good programming practice, we also call invalidate() to ensure the drawing phase as well.

提交回复
热议问题