はじめに
前回 【Android】Guidelineとは【Kotlin】 こちらの記事でGuidelineについて書きましたが、今回はそのGuidelineを調べている中で見つけた
Barrierについて調べたものを記事にします。
Barrier
Guidelineでは親Viewを基準にして補助線を引くものでしたが、
Barrierは子Viewを基準に補助線を引くものです。
constraint_referenced_ids にViewを指定することでそのViewを基準にして補助線を引くことができます。
barrierDirection でそのViewのどの位置を基準にするか指定でき、
barrierMargin でその基準からMarginを指定することができます。
例
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:barrierMargin="100dp"
app:constraint_referenced_ids="text" />
今回は ど真ん中にある”Hollo World!”の文字の左側(start)から100dpのmarginをつけた位置に補助線を指定しました
参考