20

Google published ConstraintLayout 1.1.0 beta 6 on March 22, 2018. It has a new constraint known as Optimizer. The documentation of Optimizer at https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#Optimizer does not mention when to use and why to use it. Can someone shed some light about its usage.

MMG
  • 3,226
  • 5
  • 16
  • 43
Monish Kamble
  • 1,478
  • 1
  • 15
  • 28

1 Answers1

1

Constraint Layout 1.1 adds several new optimizations that speed up your layouts. The optimizations run as a separate pass, and attempt to reduce the number of constraints needed to layout your views.

In general they work by finding constants in your layout and simplifying them.

There’s a new tag, called layout_optimizationLevel, which configures the optimization level. It can be set to the following:

  • barriers figures out where barriers are and replaces them with simpler constraints
  • direct optimizes elements directly connected to fixed element, for example the side of the screen or guidelines, and continues to optimize any elements directly connected to them
  • standard is the default optimization level which includes barriers and direct
  • dimensions is currently experimental and can cause issues on some layouts — it optimizes the layout pass by calculating dimensions
  • chains is currently experimental and figures out how to lay out chains of elements with fixed sizes.

If you want to try out the experimental optimizations dimensions and chains you can enable them on a ConstraintLayout with

<android.support.constraint.ConstraintLayout 
    app:layout_optimizationLevel="standard|dimensions|chains"

Note: To clear whole concept, you must have to implement this.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437