Platform
Android Studio
Google Play
Jetpack
Docs
Blog
Download
What's New
User Guide
Preview
Home
Platform
Android Studio
Download
What's New
User Guide
Preview
Google Play
Docs
Blog
Download a Preview
Install Alongside Stable
New Features
Release Updates
Updates archive
►
2024
2024
(82)
►
November
November
(3)
►
October
October
(8)
►
September
September
(8)
►
August
August
(9)
►
July
July
(6)
►
June
June
(7)
►
May
May
(9)
►
April
April
(9)
►
March
March
(6)
►
February
February
(8)
►
January
January
(9)
►
2023
2023
(76)
►
December
December
(4)
►
November
November
(9)
►
October
October
(7)
►
September
September
(8)
►
August
August
(3)
►
July
July
(4)
►
June
June
(6)
►
May
May
(10)
►
April
April
(4)
►
March
March
(7)
►
February
February
(9)
►
January
January
(5)
►
2022
2022
(59)
►
December
December
(3)
►
November
November
(5)
►
October
October
(8)
►
September
September
(4)
►
August
August
(4)
►
July
July
(2)
►
June
June
(7)
►
May
May
(6)
►
April
April
(5)
►
March
March
(6)
►
February
February
(5)
►
January
January
(4)
►
2021
2021
(54)
►
December
December
(3)
►
November
November
(2)
►
October
October
(6)
►
September
September
(4)
►
August
August
(5)
►
July
July
(8)
►
June
June
(4)
►
May
May
(5)
►
April
April
(1)
►
March
March
(7)
►
February
February
(4)
►
January
January
(5)
►
2020
2020
(107)
►
December
December
(7)
►
November
November
(3)
►
October
October
(8)
►
September
September
(6)
►
August
August
(11)
►
July
July
(14)
►
June
June
(10)
►
May
May
(12)
►
April
April
(11)
►
March
March
(11)
►
February
February
(6)
►
January
January
(8)
▼
2019
2019
(145)
►
December
December
(16)
►
November
November
(12)
►
October
October
(10)
►
September
September
(13)
►
August
August
(12)
►
July
July
(6)
►
June
June
(9)
►
May
May
(18)
▼
April
April
(14)
Emulator 29.0.6 canary
ConstraintLayout 2.0.0 alpha 5
Emulator 29.0.5 Canary
Android Studio 3.5 Canary 13 available
Emulator 29.0.4 Canary
Emulator 29.0.3 Canary
Android Studio 3.5 Canary 12 available
Android Studio 3.4 available in the Stable channel
Android Studio 3.5 Canary 11 available
Emulator 29.0.2 Canary
Emulator 29.0.1 Canary
ConstraintLayout 2.0.0 alpha 4
Android Studio 3.5 Canary 10 available
Android Studio 3.4 Release Candidate 3 available
►
March
March
(12)
►
February
February
(10)
►
January
January
(13)
►
2018
2018
(128)
►
December
December
(13)
►
November
November
(12)
►
October
October
(10)
►
September
September
(10)
►
August
August
(16)
►
July
July
(10)
►
June
June
(13)
►
May
May
(9)
►
April
April
(11)
►
March
March
(12)
►
February
February
(9)
►
January
January
(3)
►
2017
2017
(48)
►
December
December
(3)
►
November
November
(2)
►
October
October
(8)
►
September
September
(3)
►
August
August
(4)
►
July
July
(3)
►
June
June
(3)
►
May
May
(4)
►
April
April
(5)
►
March
March
(5)
►
February
February
(6)
►
January
January
(2)
►
2016
2016
(5)
►
December
December
(3)
►
November
November
(2)
Subscribe to updates
Posts
Atom
Posts
Android Developers
Android Studio
Preview
Release Updates
ConstraintLayout 2.0.0 alpha 5
Friday, April 26, 2019
We just released ConstraintLayout 2.0.0 alpha 5. It’s available from the google maven repository:
dependencies {
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
}
or if using the AndroidX packages:
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
}
Documentation is available on
https://developer.android.com/reference/android/support/constraint/classes.html
Examples are available on
https://github.com/googlesamples/android-ConstraintLayoutExamples
Changes
This release contains various bug fixes and performance improvements:
ConstraintLayout
New:
Flow
virtual layout
MotionLayout
Various fixes (layout updates)
Auto transition (autoTransition)
Derived Constraints (deriveConstraintsFrom)
OnSwipe regions (touchRegionId)
MotionTarget matching (layout_constraintTag, motionTarget)
OnSwipe without automatically completing (autoComplete=”false”)
If OnClick has no target id the MotionLayout is targeted
Flow Virtual layout
Flow
is a virtual layout. It can be used within a ConstraintLayout and supports multiple ways of laying out the referenced widgets (create a single chain, or multiple chains to wrap around, or a table). The advantages of being a virtual layout compared to a normal viewgroups are that:
The layout hierarchy remains flat, simplifying runtime manipulations and animations
You can constrain the Flow widget as you would any other view.
You can constrain other views to views laid out by Flow.
Within MotionLayout you can animate views into and out of a flow virtual layout, change its orientation, etc.
Flow will lay out widgets either horizontally or vertically, depending on the value of the
android:orientation
attribute. The next important attribute to set is
flow_wrapMode
, which will control how the referenced widgets are laid out in the given orientation:
app:flow_wrapMode = “none”
will create a single chain out of the referenced elements (
default
)
app:flow_wrapMode = “chain”
will create multiple chains (one after the other) if the referenced elements do not fit in the available space
app:flow_wrapMode = “aligned”
is a bit similar to wrap chain, but will align the elements, basically creating rows and columns
The way elements are positioned for the other orientation is controlled by
flow_horizontalAlign
and
flow_verticalAlign
attributes. For example, if specifying a horizontal orientation, use
flow_verticalAlign
to control the vertical positioning of the elements being laid out.
android:orientation = “horizontal|vertical”
(default horizontal)
app:flow_horizontalStyle = "spread|spread_inside|packed"
(default spread)
app:flow_verticalStyle = "spread|spread_inside|packed"
(default spread)
app:flow_horizontalBias = "float"
(default 0.5)
app:flow_verticalBias = "float"
(default 0.5)
app:flow_horizontalGap = "dimension"
(default 0)
app:flow_verticalGap = "dimension"
(default 0)
app:flow_horizontalAlign = "start|end|center"
(default center)
app:flow_verticalAlign = "top|bottom|center|baseline”
(default center)
app:flow_maxElementsWrap = "integer"
(default : 0, not applied)
New features of MotionLayout
We also added several new features to MotionLayout.
Auto Transition
Transitions can be made to automatically fire when MotionLayout reaches a state associated with that transition.
none - default value no transitions automatically
animateToStart - animate to the start state if you are at the end state
animateToEnd - animate to the end state if you are at the start state
jumpToEnd - Jump to the start state if you are at the start state
jumpToStart - Jump to the end state if you are at the end state
These can be combined to allow jumping to the end but smooth transition to the start.
<
Transition
motion
:constraintSetStart
="@+id/end"
motion
:constraintSetEnd
="@+id/b"
motion
:autoTransition
="animateToEnd"
motion
:motionInterpolator
="easeIn"
motion
:duration
="1000"
/>
Derived Constraints
Constraint sets can now be derived from other constraints sets. This can greatly reduce xml size. In a <ConstraintSet> can now have an attribute deriveConstraintsFrom which allows you to specify the id of another constraint set. This is useful for generating a series of constraints that only have small variations between them.
Note:
A constraint set represents the complete set of constraints for a layout
This works well in conjunction with the newer PropertySet, Layout, Transform syntax
All ConstraintSets derive from from the MotionLayout by default
<!-- Content of layout file -->
<
ConstraintSet
android
:id
="@+id/base"
>
</
ConstraintSet
>
<!-- Layout file but override visibility of region1 (region1 now gone ) -->
<
ConstraintSet
android
:id
="@+id/state1"
>
<
Constraint
android
:id
="@id/region1"
>
<
PropertySet
motion
:visibility
="gone"
/>
</
Constraint
>
</
ConstraintSet
>
<!-- State1 (above) but override visibility of region2 (both region1 & region2 gone) -->
<
ConstraintSet
android
:id
="@+id/state2"
motion
:deriveConstraintsFrom
="@id/state1"
>
<
Constraint
android
:id
="@id/region2"
>
<
PropertySet
motion
:visibility
="gone"
/>
</
Constraint
>
</
ConstraintSet
>
OnSwipe regions
OnSwipe now takes an attribute touchRegionId which limits the starting point of the bounds of that view.
Note:
The
view pointed to by the id
can be invisible
Quite often the region is the same as the anchor.
This allows two Transition swipes to be in effect in the same direction normally each transition is in a different direction.
<
OnSwipe
motion
:dragDirection
="dragDown"
motion
:touchAnchorId
="@+id/region2"
motion
:touchRegionId
="@+id/region2"
motion
:touchAnchorSide
="top"
/>
Swipe without autocomplete
OnSwipe Automatically completes the transition choosing the direction and animating smoothly to a stop. Sometimes this feature is not desired and can be turned off.
You can use this to implement things like a custom slider.
<
OnSwipe
motion
:dragDirection
="dragRight"
motion
:autoComplete
="false"
motion
:touchAnchorId
="@+id/button"
motion
:touchAnchorSide
="right"
/>