Slide 1

Slide 1 text

ConstraintLayout 2.0 Nicolas Roard @camaelon John Hoford @johnhoford

Slide 2

Slide 2 text

Why

Slide 3

Slide 3 text

ConstraintLayout 1.x Flat hierarchy : decouple layout from the view hierarchy Support library Powerful internal engine Design Tools : UI Builder

Slide 4

Slide 4 text

When : some guidance Simplify layouts of components Build UI quickly What about LinearLayout / FrameLayout ?

Slide 5

Slide 5 text

ConstraintLayout 2.x Flexibility Virtual Layouts Helpers & Decorators Optimizer MotionLayout Design Tools : UI Builder, Motion Editor

Slide 6

Slide 6 text

Motion Editor

Slide 7

Slide 7 text

Motion Editor

Slide 8

Slide 8 text

Architecture

Slide 9

Slide 9 text

Architecture Linear Solver

Slide 10

Slide 10 text

Architecture Constraints Model Linear Solver

Slide 11

Slide 11 text

Architecture Linear Solver Constraints Model Optimizer

Slide 12

Slide 12 text

Architecture Linear Solver Constraints Model Optimizer Virtual Layouts Helpers

Slide 13

Slide 13 text

Architecture Linear Solver Constraints Model Optimizer MotionLayout Virtual Layouts Helpers

Slide 14

Slide 14 text

ConstraintLayout

Slide 15

Slide 15 text

Layout concepts Direct Constraints : relative, circular, dimensions (ratio…) Chains Helpers : Guidelines, Barriers, Layer… Decorators Virtual Layout Constraint Sets

Slide 16

Slide 16 text

Helpers

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Encapsulate Behaviors ConstraintLayout utility Encapsulate a given behavior Apply it to a set of widgets ▸ Supported in Studio ▸ Can use View APIs (animation, etc.) in helpers to promote reuse

Slide 26

Slide 26 text

Circular Reveal

Slide 27

Slide 27 text

Circular Reveal

Slide 28

Slide 28 text

@Override public void updatePostLayout(ConstraintLayout container) { super.updatePostLayout(container); if (mContainer != container) { int rad =(int) Math.hypot(mComputedMaxY - mComputedMinY, mComputedMaxX - mComputedMinX); Animator anim = ViewAnimationUtils.createCircularReveal(this, (int) mComputedCenterX-getLeft(), (int) mComputedCenterY-getTop(), 0, rad); anim.setDuration(2000); anim.start(); } mContainer = container; }

Slide 29

Slide 29 text

@Override public void updatePostLayout(ConstraintLayout container) { super.updatePostLayout(container); if (mContainer != container) { int rad =(int) Math.hypot(mComputedMaxY - mComputedMinY, mComputedMaxX - mComputedMinX); Animator anim = ViewAnimationUtils.createCircularReveal(this, (int) mComputedCenterX-getLeft(), (int) mComputedCenterY-getTop(), 0, rad); anim.setDuration(2000); anim.start(); } mContainer = container; }

Slide 30

Slide 30 text

Slide 31

Slide 31 text

Decorators

Slide 32

Slide 32 text

public class MetaballsDecorator extends ConstraintHelper { public void updatePostLayout(ConstraintLayout container) { int[] ids = getReferencedIds(); final int count = ids.length; for (int i = 0; i < count; i++) { View view = container.getViewById(ids[i]); // do something } } @Override public void onDraw(Canvas canvas) { // do something } }

Slide 33

Slide 33 text

Bottom Panel Decorator

Slide 34

Slide 34 text

Bottom Panel Decorator

Slide 35

Slide 35 text

Bottom Panel Decorator

Slide 36

Slide 36 text

Bottom Panel Decorator

Slide 37

Slide 37 text

Bottom Panel Decorator

Slide 38

Slide 38 text

Bottom Panel Decorator

Slide 39

Slide 39 text

Virtual Layouts

Slide 40

Slide 40 text

MotionLayout

Slide 41

Slide 41 text

MotionLayout Reflect and animate between multiple states of components Coordinating motion of multiple components Support nesting MotionLayout Drive custom views

Slide 42

Slide 42 text

MotionLayout Reflect and animate between multiple states of components Coordinating motion of multiple components Support nesting MotionLayout Drive custom views

Slide 43

Slide 43 text

MotionLayout Subclass of ConstraintLayout Gets its constraints from a separate xml file. Allows you to directly animate between two Constraint sets Extensive control of the Transition between the two Custom attributes — not just layout

Slide 44

Slide 44 text

Motion concepts States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick A B

Slide 45

Slide 45 text

Motion concepts States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick A B

Slide 46

Slide 46 text

Motion concepts States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick A B

Slide 47

Slide 47 text

States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick Motion concepts

Slide 48

Slide 48 text

States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick Motion concepts

Slide 49

Slide 49 text

States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick Motion concepts

Slide 50

Slide 50 text

States (ConstraintSets) Transitions Keyframes Coordinate Systems OnSwipe/OnClick Motion concepts

Slide 51

Slide 51 text

Organisation Layout file Views Helpers VirtualLayout MotionScene file OnSwipe Constraint KeyFrameSet Transition ConstraintSet

Slide 52

Slide 52 text

Example

Slide 53

Slide 53 text

Start & End

Slide 54

Slide 54 text

Start & End

Slide 55

Slide 55 text

Positioning

Slide 56

Slide 56 text

Positioning

Slide 57

Slide 57 text

Custom Attribute : color

Slide 58

Slide 58 text

Custom Attribute : color

Slide 59

Slide 59 text

Cycles

Slide 60

Slide 60 text

Cycles

Slide 61

Slide 61 text

How to use it?

Slide 62

Slide 62 text

Coordinator Layout Collapsible Toolbar From GitHub

Slide 63

Slide 63 text

Coordinator Layout Collapsible Toolbar From GitHub

Slide 64

Slide 64 text

DrawerLayout From GitHub

Slide 65

Slide 65 text

DrawerLayout From GitHub

Slide 66

Slide 66 text

ViewPager From GitHub

Slide 67

Slide 67 text

ViewPager From GitHub

Slide 68

Slide 68 text

Coordination

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

From GitHub Nested MotionLayout

Slide 72

Slide 72 text

From GitHub Nested MotionLayout

Slide 73

Slide 73 text

Start End MotionLayout 2 MotionLayout 1

Slide 74

Slide 74 text

Chris Banes "I MotionLayout, creating complex UI animations is a breeze when you can define some keyframes and let MotionLayout handle the rest"

Slide 75

Slide 75 text

Chris Banes "I MotionLayout, creating complex UI animations is a breeze when you can define some keyframes and let MotionLayout handle the rest"

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

Cycles

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

Key Cycles KeyTimeCycles & KeyCycles

Slide 82

Slide 82 text

Key Cycles KeyTimeCycles & KeyCycles

Slide 83

Slide 83 text

Key Cycle interpolation

Slide 84

Slide 84 text

Monotonic splines • Less prone to overshoot • Needs to be differentiable and Integrable Typical Spline Monotonic Spline

Slide 85

Slide 85 text

KeyCycle •Period - 1/pos across space •Offset - shifts the envelope •Attributes - set amplitude of wave

Slide 86

Slide 86 text

KeyCycles

Slide 87

Slide 87 text

KeyCycles

Slide 88

Slide 88 text

KeyCycles Period

Slide 89

Slide 89 text

KeyCycles Period

Slide 90

Slide 90 text

KeyCycles Value

Slide 91

Slide 91 text

KeyCycles Value

Slide 92

Slide 92 text

KeyCycles offset

Slide 93

Slide 93 text

KeyCycles offset

Slide 94

Slide 94 text

KeyCycles waveShape

Slide 95

Slide 95 text

KeyCycles waveShape

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

KeyCycles multiple waves translationX translationY

Slide 99

Slide 99 text

KeyCycles multiple waves translationX translationY

Slide 100

Slide 100 text

KeyCycles multiple waves translationX translationY

Slide 101

Slide 101 text

KeyCycles multiple waves translationX translationY

Slide 102

Slide 102 text

KeyCycles multiple waves translationX translationY

Slide 103

Slide 103 text

KeyCycles multiple waves translationX translationY

Slide 104

Slide 104 text

KeyCycles imagination is the limit translationY rotation translationY rotation

Slide 105

Slide 105 text

KeyCycles imagination is the limit translationY rotation translationY rotation

Slide 106

Slide 106 text

Introducing CycleEditor • Explore the capabilities of KeyCycles • XML shown compatible with alpha3 • Features: • Graph multiple cycles • Simulate keyCycles effect on a button

Slide 107

Slide 107 text

KeyTimeCycle •Period - 1/s (Hz) •Offset - shifts the envelope •Attributes - set amplitude of wave Same attributes as KeyCycle

Slide 108

Slide 108 text

KeyTimeCycles Period (Hz) KeyTimeCycle Attribute translationX

Slide 109

Slide 109 text

KeyTimeCycles Period (Hz) KeyTimeCycle Attribute translationX

Slide 110

Slide 110 text

KeyTimeCycles (KeyPosition) Change the KeyPosition

Slide 111

Slide 111 text

KeyTimeCycles (KeyPosition) Change the KeyPosition

Slide 112

Slide 112 text

KeyTimeCycles (Attribute) Changing value of android:translationX

Slide 113

Slide 113 text

KeyTimeCycles (Attribute) Changing value of android:translationX

Slide 114

Slide 114 text

KeyTimeCycles Changing value of motion:waveOffset waveOffset

Slide 115

Slide 115 text

KeyTimeCycles Changing value of motion:waveOffset waveOffset

Slide 116

Slide 116 text

KeyTimeCycles Changing value of motion:waveShape

Slide 117

Slide 117 text

KeyTimeCycles Changing value of motion:waveShape

Slide 118

Slide 118 text

What’s new

Slide 119

Slide 119 text

Alpha 3 MotionLayout

Slide 120

Slide 120 text

alpha 3 New XML format KeyTimeCycle KeyTrigger

Slide 121

Slide 121 text

Alpha 4 MotionLayout

Slide 122

Slide 122 text

alpha 4 Richer behaviors for OnClick actions CustomAttributes support for customPixelDimensions ImageFilterView overlay support KeyTrigger collision support Attributes rename

Slide 123

Slide 123 text

MotionLayout Alpha 5

Slide 124

Slide 124 text

alpha 5 MotionTarget string matching OnSwipe regions Automatic transitions Derived ConstraintSets 


Slide 125

Slide 125 text

Target Matching

Slide 126

Slide 126 text

MotionTarget matching Two Tags: layout_constraintTag … Label a View motionTarget … Takes ID or Regular Expressions Apply one keyframe to many views

Slide 127

Slide 127 text

layout_constraintTag & motionTarget In Layout…

Slide 128

Slide 128 text

layout_constraintTag & motionTarget In Layout…

Slide 129

Slide 129 text

layout_constraintTag & motionTarget In Layout… Or in MotionScene … />

Slide 130

Slide 130 text

layout_constraintTag & motionTarget In Layout… Or in MotionScene … /> Now apply in MotionScene />

Slide 131

Slide 131 text

Region Swipe

Slide 132

Slide 132 text

Region Swipe Limiting Swipe to regions

Slide 133

Slide 133 text

Region Swipe Limiting Swipe to regions

Slide 134

Slide 134 text

dragDirection dragUp dragDown dragRight dragLeft touchAnchorId touchAnchorSide top bottom left right touchRegionId

Slide 135

Slide 135 text

Example

Slide 136

Slide 136 text

Example

Slide 137

Slide 137 text

Auto Transition

Slide 138

Slide 138 text

Auto Transition A B Transition

Slide 139

Slide 139 text

Auto Transition A B Transition

Slide 140

Slide 140 text

Auto Transition On start animation

Slide 141

Slide 141 text

Auto Transition On start animation

Slide 142

Slide 142 text

Auto Transition On start animation START Transition A B Transition

Slide 143

Slide 143 text

Auto Transition "jumpToStart" "jumpToEnd" "animateToStart" "animateToEnd"

Slide 144

Slide 144 text

Derived Constraints

Slide 145

Slide 145 text

Derived Constraint Base layout

Slide 146

Slide 146 text

Derived Constraint Base layout + view1 gone

Slide 147

Slide 147 text

Derived Constraint Base layout + view1 gone + view2 gone

Slide 148

Slide 148 text

Derived Constraint Base layout + view1 gone + view2 gone + view3 gone

Slide 149

Slide 149 text

Virtual Layout Alpha 5

Slide 150

Slide 150 text

Flow

Slide 151

Slide 151 text

Flow : Virtual Layout Helper : reference objets Keep a Flat Hierarchy On the fly changes

Slide 152

Slide 152 text

Flow modes 1. Apply an horizontal or vertical chain to the elements 2. Wrap elements as needed, using chains 3. Wrap elements as needed, aligning in rows & columns

Slide 153

Slide 153 text

Flow : a view

Slide 154

Slide 154 text

Flow : a view Flow is a perfectly normal view You can ask it to wrap_content or be of a given size You can set up a background

Slide 155

Slide 155 text

Flow : XML

Slide 156

Slide 156 text

Flow : chains

Slide 157

Slide 157 text

Flow mode : chains A B C Spread

Slide 158

Slide 158 text

Flow mode : chains A B C Spread Inside

Slide 159

Slide 159 text

Flow mode : chains A B C Packed

Slide 160

Slide 160 text

Flow : XML

Slide 161

Slide 161 text

Flow : XML

Slide 162

Slide 162 text

Flow : XML

Slide 163

Slide 163 text

Flow : Wrap Chains

Slide 164

Slide 164 text

Flow mode : wrap chains A B C D E F

Slide 165

Slide 165 text

Flow mode : wrap chains A B C D E F

Slide 166

Slide 166 text

Flow mode : wrap chains A B C D E F Wrapping Add a new chain

Slide 167

Slide 167 text

Flow mode : wrap chains A B C D E F Wrapping Spread Chain

Slide 168

Slide 168 text

Flow mode : wrap chains A B C D E F Wrapping Spread Chain Packed Chain

Slide 169

Slide 169 text

Flow mode : wrap chains A B C D E F Wrapping : max elements = 3 (wrap_content)

Slide 170

Slide 170 text

Flow mode : wrap chains A B C D E F No Table?

Slide 171

Slide 171 text

Flow : Wrap Align

Slide 172

Slide 172 text

Flow mode : wrap chains A B C D E F Wrap : chains

Slide 173

Slide 173 text

Flow mode : wrap align A B C D E F Wrap : Align

Slide 174

Slide 174 text

Example

Slide 175

Slide 175 text

Calculator

Slide 176

Slide 176 text

No content

Slide 177

Slide 177 text

Slide 178

Slide 178 text

Slide 179

Slide 179 text

Slide 180

Slide 180 text

Slide 181

Slide 181 text

No content

Slide 182

Slide 182 text

Slide 183

Slide 183 text

Slide 184

Slide 184 text

MotionLayout & Flow

Slide 185

Slide 185 text

MotionLayout with Flow

Slide 186

Slide 186 text

MotionLayout with Flow

Slide 187

Slide 187 text

MotionLayout with Flow

Slide 188

Slide 188 text

MotionLayout with Flow

Slide 189

Slide 189 text

RecyclerView + MotionLayout

Slide 190

Slide 190 text

No content

Slide 191

Slide 191 text

No content

Slide 192

Slide 192 text

No content

Slide 193

Slide 193 text

No content

Slide 194

Slide 194 text

No content

Slide 195

Slide 195 text

No content

Slide 196

Slide 196 text

How it works Handle Gesture Provide a similar view Add view to Placeholder in MotionLayout Recompute bounds Run transition

Slide 197

Slide 197 text

Handling new PlaceholderGestureHandler( motionLayout, recyclerView, view, viewType ) gestureHandler.onTouchEvent(event)

Slide 198

Slide 198 text

Basic start to end motion

Slide 199

Slide 199 text

Basic start to end motion

Slide 200

Slide 200 text

Add size delay

Slide 201

Slide 201 text

Add size delay

Slide 202

Slide 202 text

Add tilt

Slide 203

Slide 203 text

Add tilt

Slide 204

Slide 204 text

Wrapping up…

Slide 205

Slide 205 text

Timeline… Alpha 4 : released April 4th Alpha 5 : in the next few days! Beta 1 around Google IO Motion Editor : resume work after Google IO

Slide 206

Slide 206 text

developer.android.com https://developer.android.com/reference/android/support/constraint/classes.html Medium Articles: Introduction to MotionLayout part I http://bit.ly/2O4AmIz Introduction to MotionLayout part II http://bit.ly/2uPuWbw Introduction to MotionLayout part III http://bit.ly/2zRjCSj Introduction to MotionLayout part IV http://bit.ly/2QqfJaF Github: https://github.com/googlesamples/android-ConstraintLayoutExamples Documentation

Slide 207

Slide 207 text

Give us feedback! http://issuetracker.google.com ConstraintLayout component

Slide 208

Slide 208 text

Thanks! Nicolas Roard @camaelon John Hoford @johnhoford