


These will cause the constraint to be fixed at a percentage of the available space. Isn’t this fantastic? All views support layout_constraintWidth_percent and layout_constraintHeight_percent attributes. In Constraint Layout 1.1 it’s been made simpler by allowing you to easily constrain any view to a percentage width or height. Here is a more complete example that uses a guideline with additional weights: Ĭonstraint Layout 1.0 making a view take up a percentage of the screen required making two guidelines. Now it's possible to use weights: android:layout_width="0dp"Īpp:layout_constraintHorizontal_weight="1" However sometimes we want percentages without guidelines. The Guideline is invaluable - and the app:layout_constraintGuide_percent is a great friend. Use bias with app:layout_constraintHorizontal_bias and/or app:layout_constraintVertical_bias to modify view location when the available space allows Īnother percent based value is height and/or width of elements, with app:layout_constraintHeight_percent and/or app:layout_constraintWidth_percent: Ī useful addition to this is to set the other dimension relative to the first, for example - set the height according to the width, proportionally: app:layout_constraintDimensionRatio="1:1" Use a guideline with app:layout_constraintGuide_percent like this: Īnd then you can use this guideline as anchor points for other views. It may be useful to have a quick reference here.
