Slide 1

Slide 1 text

Building a Modern Android UI Nicolas Roard @camaelon John Hoford @johnhoford

Slide 2

Slide 2 text

Material Design

Slide 3

Slide 3 text

Material is the Metaphor

Slide 4

Slide 4 text

Bold Graphic Intentional

Slide 5

Slide 5 text

Motion provides Meaning

Slide 6

Slide 6 text

Intentional Motion

Slide 7

Slide 7 text

Intentional Motion

Slide 8

Slide 8 text

Guides User’s focus

Slide 9

Slide 9 text

Guides User’s focus

Slide 10

Slide 10 text

Baseline Grid

Slide 11

Slide 11 text

Keylines

Slide 12

Slide 12 text

Ratio

Slide 13

Slide 13 text

http://material.io

Slide 14

Slide 14 text

Components

Slide 15

Slide 15 text

Layout

Slide 16

Slide 16 text

Simple vs Complex LinearLayout FrameLayout TableLayout GridLayout RelativeLayout ConstraintLayout

Slide 17

Slide 17 text

ConstraintLayout

Slide 18

Slide 18 text

ConstraintLayout • Flat Layouts • Expressive Layouts • Visual Editor

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Vertical LinearLayout

Slide 22

Slide 22 text

Vertical LinearLayout RelativeLayout Image Image

Slide 23

Slide 23 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout

Slide 24

Slide 24 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView

Slide 25

Slide 25 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView

Slide 26

Slide 26 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView Horizontal LinearLayout EditText TextView

Slide 27

Slide 27 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView Horizontal LinearLayout EditText TextView TextView

Slide 28

Slide 28 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView Horizontal LinearLayout EditText TextView TextView Horizontal LinearLayout Button Button

Slide 29

Slide 29 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView Horizontal LinearLayout EditText TextView TextView Horizontal LinearLayout Button Button

Slide 30

Slide 30 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView Horizontal LinearLayout EditText TextView TextView Horizontal LinearLayout Button Button

Slide 31

Slide 31 text

Vertical LinearLayout RelativeLayout Image Image Vertical LinearLayout TextView Horizontal LinearLayout EditText TextView Horizontal LinearLayout EditText TextView TextView Horizontal LinearLayout Button Button

Slide 32

Slide 32 text

ConstraintLayout

Slide 33

Slide 33 text

ConstraintLayout Image Image TextView EditText TextView EditText TextView TextView Button Button

Slide 34

Slide 34 text

ConstraintLayout Image Image TextView EditText TextView EditText TextView TextView Button Button

Slide 35

Slide 35 text

What • Small (130 Kb) • Unbundled Library • Flexible foundation • Direct Resolution • Linear System Solver

Slide 36

Slide 36 text

What • Small (130 Kb) • Unbundled Library • Flexible foundation • Direct Resolution • Linear System Solver Linear System Solver

Slide 37

Slide 37 text

What • Small (130 Kb) • Unbundled Library • Flexible foundation • Direct Resolution • Linear System Solver Linear System Solver Constraints System

Slide 38

Slide 38 text

What • Small (130 Kb) • Unbundled Library • Flexible foundation • Direct Resolution • Linear System Solver Linear System Solver Direct Resolution Constraints System

Slide 39

Slide 39 text

What • Small (130 Kb) • Unbundled Library • Flexible foundation • Direct Resolution • Linear System Solver Linear System Solver Direct Resolution Constraints System UI Builder

Slide 40

Slide 40 text

What • Small (130 Kb) • Unbundled Library • Flexible foundation • Direct Resolution • Linear System Solver Linear System Solver Direct Resolution Constraints System UI Builder Inference

Slide 41

Slide 41 text

1.0.2 • 16 updates since Google IO’16 • Faster! • New Features • Improved Visual Editor support • Default Layout in Android Studio

Slide 42

Slide 42 text

Row

Slide 43

Slide 43 text

Row

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

How it works • Horizontal Chain, packed • Bias to 0 • Resizable element set to default=wrap

Slide 47

Slide 47 text

Gone behavior

Slide 48

Slide 48 text

Gone behavior

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Inadapted Margins?

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Gone Margins!

Slide 53

Slide 53 text

Framework & Support Lib Common patterns and components

Slide 54

Slide 54 text

Navigation Drawer

Slide 55

Slide 55 text

Navigation Drawer

Slide 56

Slide 56 text

ViewPager

Slide 57

Slide 57 text

ViewPager

Slide 58

Slide 58 text

Coordinator Layout

Slide 59

Slide 59 text

Coordinator Layout

Slide 60

Slide 60 text

Android Studio

Slide 61

Slide 61 text

Goals

Slide 62

Slide 62 text

Goals Visualize

Slide 63

Slide 63 text

Goals Visualize Create

Slide 64

Slide 64 text

Goals Visualize Create Easy

Slide 65

Slide 65 text

Goals Visualize Create Easy Efficiently

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

Tools attributes • tools: • tools:showIn • tools:layout • tools:listitem • tools:parentTag https://developer.android.com/studio/write/tool-attributes.html

Slide 77

Slide 77 text

Tools attributes • tools: • tools:showIn • tools:layout • tools:listitem • tools:parentTag override attributes at design time https://developer.android.com/studio/write/tool-attributes.html

Slide 78

Slide 78 text

Tools attributes • tools: • tools:showIn • tools:layout • tools:listitem • tools:parentTag override attributes at design time shows this layout embedded in another one https://developer.android.com/studio/write/tool-attributes.html

Slide 79

Slide 79 text

Tools attributes • tools: • tools:showIn • tools:layout • tools:listitem • tools:parentTag override attributes at design time shows this layout embedded in another one which layout to use for a fragment https://developer.android.com/studio/write/tool-attributes.html

Slide 80

Slide 80 text

Tools attributes • tools: • tools:showIn • tools:layout • tools:listitem • tools:parentTag override attributes at design time shows this layout embedded in another one which layout to use for a fragment which layout for a list item https://developer.android.com/studio/write/tool-attributes.html

Slide 81

Slide 81 text

Tools attributes • tools: • tools:showIn • tools:layout • tools:listitem • tools:parentTag override attributes at design time shows this layout embedded in another one which layout to use for a fragment which layout for a list item define which layout to use as parent for merge tag https://developer.android.com/studio/write/tool-attributes.html

Slide 82

Slide 82 text

Tip: tools attributes tools:listitem=“@layout/row” https://developer.android.com/ studio/write/tool-attributes.html

Slide 83

Slide 83 text

Useful shortcuts • to select a parent group • to switch between XML and Design mode • double-click on included elements

Slide 84

Slide 84 text

Constraint Layout Tools

Slide 85

Slide 85 text

Tools

Slide 86

Slide 86 text

Tools

Slide 87

Slide 87 text

Tools

Slide 88

Slide 88 text

Tools

Slide 89

Slide 89 text

Tools

Slide 90

Slide 90 text

Tools

Slide 91

Slide 91 text

Tools

Slide 92

Slide 92 text

Tools • Automatically makes constraints • Control for simple moving of views

Slide 93

Slide 93 text

Tools • Automatically makes constraints • Control for simple moving of views

Slide 94

Slide 94 text

Inference Automatically create constraints • Based on probability a model for connections • Constrains unconstrained views • Does not move views (not an alignment tool)

Slide 95

Slide 95 text

Inference Automatically create constraints • Based on probability a model for connections • Constrains unconstrained views • Does not move views (not an alignment tool)

Slide 96

Slide 96 text

Inference Automatically create constraints • Based on probability a model for connections • Constrains unconstrained views • Does not move views (not an alignment tool)

Slide 97

Slide 97 text

Inference Automatically create constraints • Based on probability a model for connections • Constrains unconstrained views • Does not move views (not an alignment tool)

Slide 98

Slide 98 text

Inference Automatically create constraints • Based on probability a model for connections • Constrains unconstrained views • Does not move views (not an alignment tool)

Slide 99

Slide 99 text

Inference Automatically create constraints • Based on probability a model for connections • Constrains unconstrained views • Does not move views (not an alignment tool)

Slide 100

Slide 100 text

Motion

Slide 101

Slide 101 text

Animating Content

Slide 102

Slide 102 text

Animating Content • View state change: StateListAnimator • android:stateListAnimator • Vector Drawable • + + • Reveal animation • Ripples

Slide 103

Slide 103 text

Animated Icons

Slide 104

Slide 104 text

Animated Icons

Slide 105

Slide 105 text

Combined with other animations

Slide 106

Slide 106 text

Combined with other animations

Slide 107

Slide 107 text

Activity Transitions

Slide 108

Slide 108 text

Activity Transitions • enter & exit transitions • explode, slide, fade • shared elements • bounds, clip, transform, image transform

Slide 109

Slide 109 text

Activity Transitions • enter & exit transitions • explode, slide, fade • shared elements • bounds, clip, transform, image transform

Slide 110

Slide 110 text

Layout Transitions TransitionManager

Slide 111

Slide 111 text

ConstraintSet

Slide 112

Slide 112 text

ConstraintSet

Slide 113

Slide 113 text

ConstraintSet • Separate views from how we layout them

Slide 114

Slide 114 text

ConstraintSet • Separate views from how we layout them • Encapsulate all constraints in an object

Slide 115

Slide 115 text

ConstraintSet • Separate views from how we layout them • Encapsulate all constraints in an object • You can apply a ConstraintSet to an existing ConstraintLayout

Slide 116

Slide 116 text

ConstraintSet • Separate views from how we layout them • Encapsulate all constraints in an object • You can apply a ConstraintSet to an existing ConstraintLayout • Switch between multiple ConstraintSet

Slide 117

Slide 117 text

ConstraintSet

Slide 118

Slide 118 text

ConstraintSet ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set

Slide 119

Slide 119 text

ConstraintSet ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set mConstraintSet2.clone(context, R.layout.state2); // get constraints from layout setContentView(R.layout.state1); mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main); mConstraintSet1.clone(mConstraintLayout); // get constraints from ConstraintSet

Slide 120

Slide 120 text

ConstraintSet ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set mConstraintSet2.clone(context, R.layout.state2); // get constraints from layout setContentView(R.layout.state1); mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main); mConstraintSet1.clone(mConstraintLayout); // get constraints from ConstraintSet mConstraintSet1.applyTo(mConstraintLayout);

Slide 121

Slide 121 text

Dialog

Slide 122

Slide 122 text

Dialog

Slide 123

Slide 123 text

Landscape

Slide 124

Slide 124 text

Rotation

Slide 125

Slide 125 text

Rotation

Slide 126

Slide 126 text

ConstraintLayout & Motion

Slide 127

Slide 127 text

ConstraintLayout & Motion

Slide 128

Slide 128 text

ConstraintSet ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set mConstraintSet2.clone(context, R.layout.state2); // get constraints from layout setContentView(R.layout.state1); mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main); mConstraintSet1.clone(mConstraintLayout); // get constraints from ConstraintSet mConstraintSet1.applyTo(mConstraintLayout);

Slide 129

Slide 129 text

ConstraintSet ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set mConstraintSet2.clone(context, R.layout.state2); // get constraints from layout setContentView(R.layout.state1); mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main); mConstraintSet1.clone(mConstraintLayout); // get constraints from ConstraintSet TransitionManager.beginDelayedTransition(mConstraintLayout); mConstraintSet1.applyTo(mConstraintLayout);

Slide 130

Slide 130 text

• Programmatically change individual parameters • Use TransitionManager to smooth animation Individual View Animation

Slide 131

Slide 131 text

• Programmatically change individual parameters • Use TransitionManager to smooth animation Individual View Animation

Slide 132

Slide 132 text

• Programmatically change individual parameters • Use TransitionManager to smooth animation Individual View Animation //Find the view you are over and set minimum height TransitionManager.beginDelayedTransition(myConstraintLayout); View child = myConstraintLayout.getChildAt(current); child.setMinimumHeight(400);

Slide 133

Slide 133 text

ConstraintLayout & Motion

Slide 134

Slide 134 text

ConstraintLayout & Motion • Flat Hierarchy == No clipping issues

Slide 135

Slide 135 text

ConstraintLayout & Motion • Flat Hierarchy == No clipping issues • Scene Graph

Slide 136

Slide 136 text

ConstraintLayout & Motion • Flat Hierarchy == No clipping issues • Scene Graph • ConstraintSet == Keyframe

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

No content

Slide 139

Slide 139 text

ConstraintLayout : UI director • What you can do with widgets, you can do with components • Everything is still the same • A lot more flexible • Easy to build and test

Slide 140

Slide 140 text

NavigationView

Slide 141

Slide 141 text

NavigationView

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

• |

Slide 145

Slide 145 text

• |

Slide 146

Slide 146 text

Custom Transitions • ConstraintSet • Custom TransitionSet • Support library physics TransitionManager.beginDelayedTransition(cl, new MyCustomAnimationSet())

Slide 147

Slide 147 text

Custom Transitions • ConstraintSet • Custom TransitionSet • Support library physics TransitionManager.beginDelayedTransition(cl, new MyCustomAnimationSet())

Slide 148

Slide 148 text

Visibility & Ripple

Slide 149

Slide 149 text

Visibility & Ripple

Slide 150

Slide 150 text

What’s next • Android Studio 2.4 • default RTL support in ConstraintLayout editor • Component Tree • Slice • ConstraintLayout 1.1 • Barriers • Percent dimension • Groups

Slide 151

Slide 151 text

Component Tree

Slide 152

Slide 152 text

Slice Editor

Slide 153

Slide 153 text

Slice Editor

Slide 154

Slide 154 text

Slice Editor

Slide 155

Slide 155 text

Slice Editor

Slide 156

Slide 156 text

Barriers • “min” and “max” for constraints • implemented as a virtual helper

Slide 157

Slide 157 text

Barriers • “min” and “max” for constraints • implemented as a virtual helper

Slide 158

Slide 158 text

Groups • Apply operations on a group of widget • opacity • translate • elevation • visibility

Slide 159

Slide 159 text

Match Constraints & Percent • Define a dimension as a percent of the parent

Slide 160

Slide 160 text

Fin

Slide 161

Slide 161 text

Contact Nicolas Roard @camaelon +NicolasRoard John Hoford @johnhoford +johnhoford ConstraintLayout Documentation https://developer.android.com/ reference/android/support/constraint/ package-summary.html File Bugs & Feature Requests! http://b.android.com