With a Preview 1 of Android Studio 2.2 Google released a new layout in its support library: ConstraintLayout
. With ConstraintLayout it is easier to use a Design tool in Android Studio, but I didn't find a way to use relative sizes (percents or 'weights' like in LinearLayout). Is there a way to define the constraints based on percents? E.g. make a View take 40% of a screen, create 20% margin between views, set a View's width to 50% of another View's width?
Android – How to make ConstraintLayout work with percentage values
androidandroid-constraintlayoutandroid-support-library
Related Question
- Android – How to define dimens.xml for every different screen size in android
- Android ConstraintLayout generates absolute values
- Android Studio 2.2 Preview all screen sizes missing
- Android – Is it possible to scroll a ScrollView with a ConstraintLayout in Blueprint Mode
- Android – How to put views evenly with fixed margins and dynamic widths in ConstraintLayout
Best Solution
It may be useful to have a quick reference here.
Placement of views
Use a guideline with
app:layout_constraintGuide_percent
like this:And then you can use this guideline as anchor points for other views.
or
Use bias with
app:layout_constraintHorizontal_bias
and/orapp:layout_constraintVertical_bias
to modify view location when the available space allowsSize of views
Another percent based value is height and/or width of elements, with
app:layout_constraintHeight_percent
and/orapp:layout_constraintWidth_percent
: