Home

postlayout

Postlayout is a term used in user interface (UI) development to describe code or callbacks that execute after the rendering engine has completed a layout pass. During layout, the framework measures and assigns sizes and positions to UI elements. Postlayout code runs after these final metrics are known, allowing it to read actual dimensions or perform tasks that depend on the completed layout.

Different ecosystems provide mechanisms for postlayout actions. In Android, developers commonly attach a global layout listener

Common uses include measuring final element sizes, aligning overlays or popups to the actual positions, starting

See also: layout pass, measurement, reflow, paint.

(ViewTreeObserver.OnGlobalLayoutListener)
to
react
once
the
layout
pass
has
finished
and
the
view
tree
has
a
valid
size.
In
Flutter,
the
framework
offers
addPostFrameCallback,
which
schedules
a
function
to
run
after
the
current
frame
is
laid
out
and
painted.
In
web
browsers,
postlayout
work
often
uses
requestAnimationFrame
to
run
code
on
the
next
repaint
after
layout
changes;
MutationObserver
or
resize
observers
can
also
trigger
postlayout
logic
when
DOM
geometry
changes
occur.
animations
that
require
final
geometry,
and
performing
one-time
calculations.
Considerations
include
avoiding
expensive
work
during
postlayout
to
prevent
layout
thrashing,
cleaning
up
listeners
to
avoid
memory
leaks,
and
understanding
that
multiple
postlayout
callbacks
may
fire
during
a
single
change,
so
guards
are
advisable.