ConstraintLayoutのBarrierを知らず最近発見したので今更ですが記事にしてみようと思います。
公式リファレンス
.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.Barrier
android:id="@+id/vertical_barrier"
android:layout_width="0dp"
android:layout_height="0dp"
app:barrierDirection="start"
app:barrierMargin="28dp"
app:constraint_referenced_ids="text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
今回は対象とするViewなどは省略してます。
constraint_referenced_ids
に対象とするViewのidを設定します。
barrierDirection
に方向を指定します今回はstartなのでconstraint_referenced_ids
に設定したViewの左側からbarrierMargin="28dp"
の位置に補助線を引いています。
Barrierは補助線だと思います。
Viewに表示はされないけど、ConstraintLayoutの制約をViewの少しずらした箇所に設定したい時などに使用すると良さそうです。