Skip to content

MotionLayout Performance

John Hoford edited this page Aug 10, 2022 · 1 revision

MotionLayout is a large complex layout that that with care can be used to create highly performant animated UI. In many cases effects are added to the animation till it exceeds the budget and then it is reduced.

There are 3 areas to be concerned about in performance of MotionLayout

  1. Inflation - Large collections of XML can be expensive to parse.
  2. Normal Layout - The Multiple ConstraintSets can make Layout more expensive
  3. Animation - Animation can be the most challenging because it has to hit 30-120fps

Inflation

MotionLayout can have very complex ConstraintSets that need to be loaded during inflation

Normal Layout

When in transition a layout of MotionLayout requires evaluation of the layout of two constraintSets. if in between states it will then need to build up monotonic splines for every object that needs to move.

Animation

For smooth animation it requires the screen to be redrawn up to 120 times a second. Rendering complex scenes can prove expensive. Things to watch out for

  • Transparency - this requires multiple layers to be completely rendered.
  • Shadows - Shadows are computed and can be expensive.
  • Changing dimensions of objects. (Strict translation is much cheaper)