Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make your app dance with MotionLayout

Britt Barak
August 28, 2018

Make your app dance with MotionLayout

Intro to the brand new MotionLayout (ConstraintLayout 2.0). How and why to use it to animate your Android app and make it dance ~*~*~*

Happy people - dance. Happy apps - animate!
Happy devs - easily write delightful apps which make their users happy!

2 years ago, when ConstraintLayout was born, it added to the family performat expressive layouts. Since then, it grew and evolved, and became abundant with powerful animation opportunities!

ConstraintSet, Key Frames and the new shiney MotionLayout - this session will utilize them all to make your apps dance, and your users happy!

Presented at DroidconNYC 2018

Britt Barak

August 28, 2018
Tweet

More Decks by Britt Barak

Other Decks in Technology

Transcript

  1. Have you met MotionLayout? •Motion driven by user interaction •Extends

    ConstraintLayout •ConstraintLayout 2.0 (alpha 2) •Support from API-14 Gif: @Opintrius @BrittBarak
  2. Custom Attributes •Name from getter / setter •Type •Color •Dimension

    •Integer •Float •String •Boolean @BrittBarak
  3. <MotionScene ... > <Transition ... motion:constraintSetStart= "@layout/keypad_down" motion:constraintSetEnd =“@layout/keypad_up” >

    <OnClick motion:mode="toggle" motion:target="@id/btn_drag_keypad" /> </Transition> </MotionScene> scene_call.xml @BrittBarak
  4. <MotionScene ... > <Transition ... motion:constraintSetStart= "@layout/keypad_down" motion:constraintSetEnd =“@layout/keypad_up” >

    <OnClick motion:mode="toggle" motion:target="@id/btn_drag_keypad" /> </Transition> </MotionScene> scene_call.xml @BrittBarak
  5. <MotionScene ... > <Transition ... motion:constraintSetStart= "@id/keypad_down" motion:constraintSetEnd =“@id/keypad_up” >

    <OnClick motion:mode="toggle" motion:target="@id/btn_drag_keypad" /> </Transition> </MotionScene> scene_call.xml @BrittBarak
  6. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> </ConstraintSet> <ConstraintSet

    android:id="@+id/keypad_up"> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  7. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> </ConstraintSet> <ConstraintSet

    android:id="@+id/keypad_up"> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  8. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> <Constraint …/>

    <Constraint …/> <Constraint …/> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  9. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> <Constraint …/>

    <Constraint …/> <Constraint …/> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  10. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> <Constraint android:id=“@id/iv_avatar"

    android:layout_width="@drawable/avatar" android:layout_height="@drawable/avatar" motion: layout_constraintStart_toStartOf="parent" motion: layout_constraintTop_toTopOf=“parent”…/> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  11. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> <Constraint android:id=“@id/iv_avatar"

    android:layout_width="@drawable/avatar" android:layout_height="@drawable/avatar" motion: layout_constraintStart_toStartOf="parent" motion: layout_constraintTop_toTopOf=“parent”…/> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  12. <MotionScene ... > <Transition ... /> <ConstraintSet android:id=“@+id/keypad_down”> <Constraint android:id=“@id/iv_avatar"

    android:layout_width="@drawable/avatar" android:layout_height="@drawable/avatar" motion: layout_constraintStart_toStartOf="parent" …/> </ConstraintSet> </MotionScene> scene_call.xml @BrittBarak
  13. Image Attributes •saturation •0 = grayscale —> 1 = original

    —> 2 = hyper saturated •contrast •0= gray —> 1 = unchanged —> 2 = high contrast •warmth •0.5 = cold (blue tint) —>1 = neutral —> 2 = warm (red tint) •crossfade •0 = src —> 1 = app:altSrc @BrittBarak
  14. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  15. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  16. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  17. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  18. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  19. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  20. Recap 1. Create a MotionLayout 2. Create MotionScene 3. Define

    ConstraintSet Start & ConstraintSet End •In Layout •In MotionScene 4. Tie up Layout & MotionScene 5. CustomAttributes & ImageFilterView @BrittBarak
  21. Activity / Fragment listener = object : ViewPager.OnPageChangeListener { override

    fun onPageScrolled(…) { motionLayout.progress = (position + positionOffset) / (viewpager.adapter!!.count - 1) } } viewpager.addOnPageChangeListener(listener) @BrittBarak
  22. Activity / Fragment listener = object : ViewPager.OnPageChangeListener { override

    fun onPageScrolled(…) { motionLayout.progress = (position + positionOffset) / (viewpager.adapter!!.count - 1) } } viewpager.addOnPageChangeListener(listener) @BrittBarak
  23. Activity / Fragment listener = object : ViewPager.OnPageChangeListener { override

    fun onPageScrolled(…) { motionLayout.progress = (position + positionOffset) / (viewpager.adapter!!.count - 1) } } viewpager.addOnPageChangeListener(listener) @BrittBarak
  24. Activity / Fragment listener = object : ViewPager.OnPageChangeListener { override

    fun onPageScrolled(…) { motionLayout.progress = (position + positionOffset) / (viewpager.adapter!!.count - 1) } } viewpager.addOnPageChangeListener(listener) @BrittBarak
  25. Activity / Fragment listener = object : ViewPager.OnPageChangeListener { override

    fun onPageScrolled(…) { motionLayout.progress = (position + positionOffset) / (viewpager.adapter!!.count - 1) } } viewpager.addOnPageChangeListener(listener) @BrittBarak
  26. How to DANCE with MotionLayout? 1. Setup Layout 1. Wrap

    with MotionLayout 2. Extract views to upper level layout @BrittBarak
  27. How to DANCE with MotionLayout? 2. Define Start & Ends

    Scenes 1. In Layouts 2. Extract the constraints into MotionScene layout Start End @BrittBarak
  28. How to DANCE with MotionLayout? 2. Define Start & Ends

    Scenes 1. In Layouts 2. Extract the constraints into MotionScene Start End Scene layout @BrittBarak
  29. constraintSet constraintSet How to DANCE with MotionLayout? 2. Define Start

    & Ends Scenes 1. In Layouts 2. Extract the constraints into MotionScene Start End Scene layout @BrittBarak
  30. constraintSet constraintSet How to DANCE with MotionLayout? 2. Define Start

    & Ends Scenes 1. In Layouts 2. Extract the constraints into MotionScene Start End Scene layout @BrittBarak
  31. Resources •Big THANK YOU John Hoford & Nicolas Road!! •Blog

    Medium posts series by Nicolas @BrittBarak
  32. Resources •Big THANK YOU John Hoford & Nicolas Road!! •Blog

    Medium posts series by Nicolas • And… I’ll share mine soon! Promise @BrittBarak
  33. Resources •Big THANK YOU John Hoford & Nicolas Road!! •Blog

    Medium posts series by Nicolas • And… I’ll share mine soon! Promise @BrittBarak