Sobes.tech
Junior — Middle

What is the difference between using requestLayout and invalidate methods during interface update?

sobes.tech AI

Answer from AI

The requestLayout() method is used to notify the system that the size or position of a View has changed and a layout recalculation is needed. When this method is called, a new measurement and layout pass occurs.

The invalidate() method signals that the content of the View has changed and needs to be redrawn (calling the onDraw method). The layout is not recalculated, only the visual display is updated.

In summary:

  • requestLayout() — recalculates the size and position of the View.
  • invalidate() — redraws the View without changing its size.

Example:

view.requestLayout(); // if size parameters have changed
view.invalidate();    // if only the content for drawing has changed
What is the difference between using requestLayout… - sobes.tech