Skip to content

ConstraintLayout Tools

Question

ConstraintLayout - guidelines vs barriers, groups

Short interview answer

A guideline is a fixed or proportional invisible reference line; a barrier positions itself from the edge of referenced views; a group controls the visibility of several views together. They describe different kinds of layout relationships.

Detailed answer

Use a guideline when several elements share a design alignment, a barrier when a control must begin after whichever referenced label is widest, and a group for views that appear or disappear together:

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/contentGuideline"
    app:layout_constraintGuide_percent="0.32" />

<androidx.constraintlayout.widget.Barrier
    android:id="@+id/labelEnd"
    app:barrierDirection="end"
    app:constraint_referenced_ids="title,subtitle" />

These helpers keep the relationship declarative instead of calculating positions in code.

Sources