I am quite new to Android development and today I wondered what the 'Vertical Bias' respectively the 'Horizontal Bias' is used for in the 'ConstraintLayout'.
Asked
Active
Viewed 1.7k times
21
-
7Bias, in terms of `ConstraintLayout`, means "if there is extra room, slide the widget in this direction along the axis". The default bias is 0.5, meaning that the widget is centered in the available space. For the horizontal axis, 0.0 means "slide the widget all the way towards the `start` side" and 1.0 means "slide the widget all the way towards the `end` side". – CommonsWare Oct 17 '21 at 12:43
1 Answers
31
In short - it tells the layout how to place a view between the constrained views. If Your view inside ConstraintLayout has these:
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
it will be placed in the middle by default.
But You can add:
app:layout_constraintHorizontal_bias="1" to place it at the end of the constraint (parent in this example)
app:layout_constraintHorizontal_bias="0" to place it at the beginning of the constraint (parent in this example)
app:layout_constraintHorizontal_bias="0.33" to place it on/third of the space from the begining of the constraint (parent in this example)
etc.
Vertical bias does the same vertically.

Miłosz
- 637
- 1
- 7
- 13
-
1So that means `app:layout_constraintHorizontal_bias="0.5"` and `app:layout_constraintVertical_bias="0.5"` are the (implicit) defaults. Was wondering why the IDE kept adding them whenever I attached the vertical/horizontal constraints to parents via the GUI. – M.Ed Jul 10 '22 at 17:39
-