1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ConstraintLayoutのBarrierとは?

Last updated at Posted at 2023-06-18

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の少しずらした箇所に設定したい時などに使用すると良さそうです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?