Chain Style

Dikkat ettiyseniz yukarıda Örnek-1 ismiyle yaptığımız örneğimizde herhangi bir Chain Style’lı tanımlamadık. Ancak örnek çalıştığı zaman aşağıdaki resimde görüleceği gibi “Spread Chain” davranışı sergiledi. Bunun nedeni, eğer style belirtilmezse, default style şeklinin “Spread Chain” olması nedeniyledir ve aşağıdaki gibi kullanılır.

CHAIN_SPREAD app:layout_constraintVertical_chainStyle="spread" app:layout_constraintHorizontal_chainStyle="spread"

Bir diğer kullanım şekli de “Spread Inside Chain” dir. Bu kullanımda Spread Chain’de olduğu gibi horizontal chain için sol ve sağ taraftaki eşit uzaklıklı boşluklar bulunmaz, kenarlara yapışık konumdadır. Kullanım şekli de aşağıdaki gibidir.

CHAIN_SPREAD_INSIDE app:layout_constraintHorizontal_chainStyle="spread_inside" app:layout_constraintVertical_chainStyle="spread_inside"

Örnek-2:

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1"
    app:layout_constraintEnd_toStartOf="@+id/button2"
    app:layout_constraintHorizontal_chainStyle="spread_inside"
    app:layout_constraintStart_toStartOf="parent" />
<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/button" />

Chain’lerin bir diğer kullanım şekli de “Packed” tir. Chain Style değerinde “packed” olarak verilmesi, bileşenlerin bir arada toplu olarak gösterilmesini sağlayacaktır. Kullanım şekli de aşağıdaki gibidir.

CHAIN_PACKED app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintVertical_chainStyle="packed"

Örnek-3:

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1"
    app:layout_constraintEnd_toStartOf="@+id/button2"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintStart_toStartOf="parent" />
<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/button" />

Packed Chain’ler aynı zamanda Bias değeri verilerek kullanılabilir.

Örnek-4:

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1"
    app:layout_constraintEnd_toStartOf="@+id/button2"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintHorizontal_bias="0.2"
    app:layout_constraintStart_toStartOf="parent" />
<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/button" />

Last updated