Why do we need another layout? ● Existing Layouts are not performant as top level layouts. ● There needs to be a layout to bridge this gap and be the suitable standard for an ideal top level view group. ● Should have the performance of non weighted Linear Layout and the flexibility of a Relative Layout.
Constraint Layouts ● Meant to be the top level view of a layout. ● Although you can edit a ConstraintLayout in XML, you never have to. ● Part of the Support Library. ● Compatible with Android 2.3 (Gingerbread) and higher. ● Currently in preview.
Constraint Format layout_constraint[SourceAnchor]_[TargetAnchor]="[TargetId]" Example app:layout_constraintTop_toTopOf="@+id/guideline2" app:layout_constraintRight_toLeftOf="@+id/guideline"
Visual Layout Editor AutoConnect Automatically adds constraints to new view when added Existing views remain untouched Connections are typically made to the nearest views Infer Constraints are added to existing views Does not touch constraints which were explicitly added
View Sizes ● Wrap Content ○ Measure just large enough to fit view contents ○ layout_width = “wrap_content” ● Fixed Size ○ Measure to specified dimension ○ layout_width = “100dp” ● Any Size ○ Fill the space allowed by constraints ○ Layout_width = “0dp”
Bias ● When a view is constrained on both sides of the same axis, it will be spaced evenly between the two target anchor points by default. ● But you are allowed to specify bias to give more weight to a particular constraint ● Similar to LinearLayout/GridLayout but now you don’t necessarily have to take the available space.