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

Introduction to MotionLayout

< B@!uS />
October 28, 2018

Introduction to MotionLayout

< B@!uS />

October 28, 2018
Tweet

Other Decks in Technology

Transcript

  1. 2 @sbkurs Introduction to MotionLayout ConstraintLayout Flat view hierarchy Great

    Layout Editor Complex animations using Transition Manager From Android developers blog
  2. 4 @sbkurs Introduction to MotionLayout Animated Vector Drawable Property Animation

    framework LayoutTransition animations LayoutTransitions with TransitionManager CoordinatorLayout ANIMATIONS
  3. 9 @sbkurs Introduction to MotionLayout • A mix between the

    property animation framework, layout transitions with TransitionManager, and CoordinatorLayout MotionLayout • Let’s you describe the transition between two layouts (like TransitionManager) • Supports seek-able transitions (like CoordinatorLayout) • Can animate any property (like Property Animations)
  4. 11 @sbkurs Introduction to MotionLayout <androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http:!//schemas.android.com/apk/res/android" xmlns:app="http:!//schemas.android.com/apk/res-auto" xmlns:tools="http:!//schemas.android.com/tools" android:id="@+id/mainMotionLayout"

    android:layout_width="match_parent" android:layout_height=“match_parent" app:layoutDescription="@xml/main_view_scene" > !!!<!--Views Goes here——> !</androidx.constraintlayout.motion.widget.MotionLayout
  5. 12 @sbkurs Introduction to MotionLayout <androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http:!//schemas.android.com/apk/res/android" xmlns:app="http:!//schemas.android.com/apk/res-auto" xmlns:tools="http:!//schemas.android.com/tools" android:id="@+id/mainMotionLayout"

    android:layout_width="match_parent" android:layout_height=“match_parent" app:layoutDescription="@xml/main_view_scene" > !!!<!--Views Goes here——> !</androidx.constraintlayout.motion.widget.MotionLayout app:layoutDescription="@xml/main_view_scene"
  6. 14 @sbkurs Introduction to MotionLayout create xml file under xml

    directory Creating MotionScene <?xml version="1.0" encoding="utf-8"?> <MotionScene xmlns:android="http:!//schemas.android.com/apk/res/android" xmlns:motion="http:!//schemas.android.com/apk/res-auto"> !</MotionScene> MotionScene contains ConstraintSets and Transition
  7. 15 @sbkurs Introduction to MotionLayout ConstraintSet • Resting state •

    Has Constraints as children • Contains an id will be used by Transition • Encapsulate all the positioning rules for your layout • Constraint element should contain all constraints you want to apply to a view.
  8. 16 @sbkurs Introduction to MotionLayout <?xml version="1.0" encoding="utf-8"?> <MotionScene xmlns:motion=“http:!//schemas.android.com/apk/res-auto”>

    <ConstraintSet android:id="@+id/scene_start"> <Constraint!/> !</ConstraintSet> <ConstraintSet android:id="@+id/scene_end"> <Constraint!/> !</ConstraintSet> !</MotionScene>
  9. 18 @sbkurs Introduction to MotionLayout Transition • Defines a transition

    between two ConstraintSets • Contains Interactions • Contains KeyFrameSet
  10. 20 @sbkurs Introduction to MotionLayout <?xml version="1.0" encoding="utf-8"?> <MotionScene xmlns:motion=“http:!//schemas.android.com/apk/res-auto”>

    <Transition motion:constraintSetEnd="@id/scene_end" motion:constraintSetStart=“@id/scene_start"!/> <ConstraintSet android:id=“@+id/scene_start"> <Constraint!/> <Constraint!/> <Constraint!/> !</ConstraintSet> <ConstraintSet android:id="@+id/scene_end"> <Constraint!/> <Constraint!/> <Constraint!/> !</ConstraintSet> !</MotionScene>
  11. 22 @sbkurs Introduction to MotionLayout OnSwipe • This will drive

    the transition , by matching the motion of your finger • Parameters ★ touchAnchorId : id of the Object we should track ★ touchAnchorSide : the side of the Object that should track your finger ★ dragDirection: the direction of the motion you are tracking
  12. 25 @sbkurs Introduction to MotionLayout MotionLayout attributes for Development •

    app:layoutDescription=”reference” • app:showPaths=”boolean” • app:progress=”float”
  13. 27 @sbkurs Introduction to MotionLayout CustomAttributes • MotionLayout supports these

    attributes out of the box • alpha • visibility • elevation • rotation, rotation[X/Y] • translation[X/Y/Z] • scaleX/Y • Need of CustomAttributes?
  14. @sbkurs Introduction to MotionLayout <Constraint> <CustomAttribute motion:attributeName="backgroundColor" motion:customColorValue="#D81B60" !/> !</Constraint>

    • We specify attributeName, which matches the setter/getter of Object • Value Type also need to be specified • customColorValue • customIntegerValue • customFloatValue • customStringValue • customDimension • customBoolean • We can declare in both ConstarintSets and KeyAttribute elements
  15. 29 @sbkurs Introduction to MotionLayout CustomAttribute background is changing <ConstraintSet

    android:id=“@+id/scene_end"> <Constraint> <CustomAttribute motion:attributeName="backgroundColor" motion:customColorValue="@color/colorAccent" !/> !</Constraint> !</ConstraintSet> <ConstraintSet android:id=“@+id/scene_end"> <Constraint> <CustomAttribute motion:attributeName="backgroundColor" motion:customColorValue="@color/colorPrimary"!/> !</Constraint> !</ConstraintSet>
  16. 31 @sbkurs Introduction to MotionLayout • These are Intermediate states

    - a state to go through but not to stay in KeyFrames • KeyFrames lets you specify a change at a point in time during the transition • Different type of KeyFrames ✦ KeyPosition ✦ KeyAttribute ✦ KeyCycle ✦ KeyTimeCycle • Important attributes for every KeyFrame ★ motion:framePosition ★ motion:target
  17. 32 @sbkurs Introduction to MotionLayout KeyPosition • Specify an intermediary

    position at a particular time in transition • Allows to manipulate the motion path of widget • KeyPosition need to contain following attributes ★ target ★ framePosition ★ keyPositionType ★ percentX / percentY
  18. 33 @sbkurs Introduction to MotionLayout Image is going through intermediary

    position <KeyFrameSet> <KeyPosition motion:framePosition="50" motion:keyPositionType="pathRelative" motion:percentX="0.5" motion:percentY="0.3" motion:target="@id/imageViewFour" motion:transitionEasing="decelerate" !/> !</KeyFrameSet>
  19. 34 @sbkurs Introduction to MotionLayout KeyAttribute • Specify widget attribute

    changes at a particular time in transition • Depending on which SDK level you target for your application, some attributes may will not work • Can contain CustomAttributes
  20. 35 @sbkurs Introduction to MotionLayout Image is going through intermediary

    attribute change <KeyFrameSet> <KeyAttribute android:rotation="-45" android:scaleX="2" android:scaleY="2" motion:framePosition="50" motion:target="@id/imageViewSeven" !/> !</KeyFrameSet>
  21. 36 @sbkurs Introduction to MotionLayout TODO • KeyCycle • KeyTimeCycle

    • MotionHelper • StateSet • ImageFilterView • ArcMotion using KeyPosition Frame
  22. 38 @sbkurs Introduction to MotionLayout Lets do some Coding Dev101

    App - Introduction of a developer References: http://tiny.cc/motionlayout MotionLayout Series by Nicolas Road Code lab at : balusangem.github.io/motionlayoutintro