Reputation: 421
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?
Upvotes: 1
Views: 4518
Reputation: 1240
Horizontal biasing does not work if you are using a horizontal chain among your views (as you're giving biasing in the same axis, vertical biasing would work if there is a horizontal chain and vice-versa); except for the case if you want to apply it on your created chain's head view (which is the left-most view in a horizontal chain and the top-most view in a vertical chain); which is not your case, here. Also, the applied biasing on the head view of the chain only works if the selected chain style is packed. So, you should try and find some other workaround to achieve your desired UI and ignore the use of chain (here).
For more information, refer: Build a Responsive UI with ConstraintLayout
I hope my answer helps you.
Upvotes: 5
Reputation: 1891
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.
Upvotes: 3