We just released ConstraintLayout 2.0.0 alpha 3. It’s available from the google maven repository:
dependencies {
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha3'
}
or if using the AndroidX packages:
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
}
Changes
This release contains various bug fixes and performance improvements:
- Barrier fixes
- Chains optimizations
- Fixed glitches in MotionLayout touch handling (end state could be triggered incorrectly)
We also added several new features to MotionLayout:
- New XML format for specifying ConstraintSets, allowing finer-grained overrides
- KeyTimeCycle : a keyframe that allows you to define a cycle driven by time instead of by the transition (e.g. a pulsating color defined this way will keep pulsating even if the overall transition is stopped)
- KeyPosition now supports percentWidth/percentHeight
- KeyTrigger : a keyframe that can fire callbacks depending on the current animation progress
- Supports custom interpolators (referencing a Framework XML interpolator)
- Touch interactions can now drive multiple state transitions seamlessly one after another
- OnClick: now supports multiple OnClick per MotionScene. Important: motion:mode has been renamed to motion:clickAction.
- Added ImageFilterButton, an equivalent of ImageFilterView but extending ImageButton
- Added new callbacks in TransitionListener
New XML Format for ConstraintSet
An important addition in alpha 3 is a new way of defining ConstraintSet in the MotionScene file. Previously, <Constraint> elements had to contain all attributes defined on a view (as we replace everything when you apply them). Now, you can instead only add the specific areas you are modifying, as sub-elements of <Constraint>:
- <Layout> : layout-related (constraints) attributes
- <PropertySet> : visibility, alpha and progress
- <Transform> : scale, translation, rotation, pivot, elevation
- <Motion> : easing, arc motion, etc.
For example, let's say that you wanted to only modify the rotation of a widget in a ConstraintSet. Previously you would have needed to repeat all the attributes to preserve the position of the widget:
<Constraint
android:id="@+id/button"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginTop="100dp"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintTop_toTopOf="parent"
android:rotation="45" />
With alpha 3 you can instead only specify the Transform area, the rest will be unaffected:
<Constraint android:id="@+id/button">
<Transform motion:rotation="45" />
</Constraint>