-
Notifications
You must be signed in to change notification settings - Fork 171
ConstraintLayout Performance
With any layout it is possible to have performance issues.
##Simplified Overview of ConstraintLayout
ConstraintLayout describes the position of Widgets through a series of "Constraints" connections between Anchors with a possible margin. There are 4 or 5 Anchors on each widget Top, Bottom, Left, Right and optionally BaseLine Besides Anchors there are several parameters that control the dimension of a widgets generally they can be
- fixed - some hardcoded value
- wrapped - The widget reports a desired size
- min, max - limits on size
- aspectRation - constraining the ratio of width to height
There are a few additional features
chains - a specific pattern of Constraints that defines a behavior of a set of widgets in one dimensions
Guidelines - A vertical or horizontal line placed in a fixed location from the left right or percentage of the screen
Barrier - A vertical or horizontal line that is set to the minimum or maximum of a collection of widgets referenced widgets
Beyond that there are a collect of "Helpers" which can effect a collection of referenced widgets.
Without optimization all Constraints, Dimensioned behavior and Helpers are turned into equations in a Numeric solver. Optimization directly solves simple cases greatly reducing the compute time.
ConstraintLayout has 2 major areas of performance concerns
- Inflation - when the xml is read
- Layout - when the position of the widgets is resolved.
Generally speaking not much can be done about inflation time. More Views/Attributes means more to parse.
The way a layout is designed can greatly affect the performance.
There are some simple rules to guide performance.
The computation scales greater than linear so if it is small the performance is very fast.
Because of the complex relationship between the constrained widgets and the bounds of the ConstraintLayout it tends to push all equations into the solver