androidandroid-constraintlayoutconstraint-layout-chains

Bias attribute is ignored


I have a simple layout of horizontally chained views with spread_inside chain style. When I try to move the views using the bias attribute to desired position I've found out that bias attribute is ignored.

Here is layout for reference:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <View
        android:id="@+id/view_1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toStartOf="@id/view_2"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_2"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toStartOf="@id/view_3"
        app:layout_constraintStart_toEndOf="@id/view_1"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_3"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.2"
        app:layout_constraintStart_toEndOf="@id/view_2"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Here I would like to move the view_3 closer to view_2 using layout_constraintHorizontal_bias attribute. How can I achieve that?


Solution

  • You can change first view (chain head view) like this:

     <View
        android:id="@+id/view_1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@android:color/black"
        app:layout_constraintEnd_toStartOf="@+id/view_2"
    
        app:layout_constraintHorizontal_bias="0.1"
        app:layout_constraintHorizontal_chainStyle="packed"
    
        app:layout_constraintStart_toStartOf="parent" />
    

    and set all chain position relative to parent via layout_constraintHorizontal_bias, but inside chain this doesn't work.