I'm learning about custom views and wanted to learn about invalidate()
and requestLayout()
.
Please refer to this answer and its diagram:
https://mcmap.net/q/117846/-usage-of-forcelayout-requestlayout-and-invalidate
invalidate()
tells Android that the state of the view has changed and needs to be re-drawn.
requestLayout()
means the size of the view may have changed and needs to be remeasured, and then re-drawn.
invalidate()
will invoke dispatchDraw()
, draw()
, and onDraw()
hence it re-renders the view.
requestLayout()
on the other hand does pretty much everything from measuring to re-rendering again.
Why do so many of the examples out there (even the TextView
source code) call invalidate()
and then requestLayout()
right on the next line?