Introduction to
Motion Layout
Saurabh Arora
Rakuten Viki
@saurabh_arora90
Slide 2
Slide 2 text
Dev asked to work on animations
Slide 3
Slide 3 text
Devs after motion layout
Slide 4
Slide 4 text
Constraint Layout
● Complex layouts with a flat hierarchy
● Specifying constraints on views w.r.t other views
● Helpers such as Barriers, Groups & Guidelines
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
Constraint Set
● Create another layout file with end state
● Pick constraints from end state layout file
● Apply constraints to constraint layout
● Use transition manager for smooth transition
Slide 8
Slide 8 text
private val start: ConstraintSet by lazy {
val set = ConstraintSet()
set.clone(this, R.layout.start)
set
}
Slide 9
Slide 9 text
private val start: ConstraintSet by lazy {
val set = ConstraintSet()
set.clone(this, R.layout.start)
set
}
private val end: ConstraintSet by lazy {
val set = ConstraintSet()
set.clone(this, R.layout.end)
set
}
Motion Layout
● Introduced in ConstraintLayout 2.0
● Subclass of ConstraintLayout
● Works with touch system
● Support for intermediate states (keyframes)
● Fully declarative
Slide 16
Slide 16 text
.......
Slide 17
Slide 17 text
.......
Slide 18
Slide 18 text
.......
Slide 19
Slide 19 text
Motion Scene
Constraint Set
Transition
Constraints
Attributes
OnClick OnSwipe
KeyFrame Set
KeyPosition
KeyAttribute
private val start: ConstraintSet by lazy {
val set = ConstraintSet()
set.clone(this, R.layout.start)
set
}
private val end: ConstraintSet by lazy {
val set = ConstraintSet()
set.clone(this, R.layout.end)
set
}
.......
TransitionManager.beginDelayedTransition(layoutRoot)
end.applyTo(layoutRoot)
Recap
● Part of constraint layout 2.0 - alpha release
● Works with both position/layout and styling attributes
● Interruptible and can set progress
Slide 75
Slide 75 text
A mix between the property animation
framework, layout transitions with
TransitionManager, and
CoordinatorLayout
- Nicolas Roard
Slide 76
Slide 76 text
Devs after motion layout
Slide 77
Slide 77 text
Didn't cover
● States and Variants
● Transition easing
● KeyCycles
Slide 78
Slide 78 text
What’s next
● Better Tooling
● Motion editor
Slide 79
Slide 79 text
Resources
● Google IO'18 Talk
● Introduction to Motion Layout by Nicolas Roard
● Github : MotionLayout-Playground :
https://github.com/saurabharora90/MotionLayout-Playground