Junior — Middle
Is it necessary to call onDraw() when requestLayout() is invoked?
sobes.tech AI
Answer from AI
Calling the requestLayout() method does not guarantee an immediate call to onDraw().
requestLayout() initiates a recalculation of the View's layout and size, which involves calling onMeasure() and onLayout(). After these steps are successfully completed, the system decides whether the View needs to be redrawn, and if so, calls onDraw().
Therefore, onDraw() is not necessarily called immediately after requestLayout(), but only if a redraw is required as a result of the changes.
If you need to force a redraw without changing size or layout, you should use invalidate(), which directly triggers a call to onDraw().