Motion Layout and Motion Scene

Motion layout is a layout that helps you for managing motions of view objects or to create an animation.MotionLayout bridges the gap between layout transitions and complex motion handling, offering a mix of features between the property animation frame…


This content originally appeared on Level Up Coding - Medium and was authored by Karishma Agrawal

Motion layout is a layout that helps you for managing motions of view objects or to create an animation.MotionLayout bridges the gap between layout transitions and complex motion handling, offering a mix of features between the property animation framework, TransitionManagerand CoordinatorLayout.

In this article, I’ll discuss how we can achieve CollapsingToolBar behavior by MotionLayout. How to create MotionScene and use of each attribute.

You can use either just Motion layout makes easy to implement complex animations.

Collapsing toolbar V/S Motion layout

Collapsing Toolbar : This is part of the material design library.

what’s app profile

Sample code to design something like this will be below:

Now if we want to change the toolbar color and to hide any view, we have to manually write code in our class file.

Run the app and when you will scroll the view, it will change the toolbar color into green ad collapse the big image into toolbar.

Now let’s do the same behavior using MotionLayout.

MotionLayout :

It is part of the constraint layout.

  1. Add the ConstraintLayout dependency: Add Constraint 2.0 in your build.gradle file to support Motion layout.

2. Create a MotionLayout file:

Replace the parent layout from ConstraintLayout to MotionLayout and all the properties will remain the same. In our layout XML file, we will write code for initial screen which we want to see before animation starts.

3. Create a MotionScene: In the previous Motion layout XML file we have a property app:layoutDescription , we add motion scene file there.

Path of the motion scene file
  • ConstraintSet: In this section we defines constraint of a layout like width, height and alignment. In this example app:layout_constraintEnd_toEndOf=”parent”, app:layout_constraintStart_toStartOf=”parent”, app:layout_constraintTop_toTopOf=”parent” properties are getting changed.
  • Transition: It contains the base definition of the motion. motion:constraintSetStart and motion:constraintSetEnd are references to the start and end points of the motion. As you can see in about file motion:constraintSetStart contains id of <ConstraintSet android:id=”@+id/expand”> that mean it is start state of animation. motion:constraintSetEnd contains id of <ConstraintSet android:id=”@+id/collapsed”> tha mean when you will scroll the layout it will pick this layout state. There is one more property motion:duration that specifies the number of milliseconds that it takes for the motion to complete.
  • OnSwipe: It lets you control the motion via touch.
    motion:touchAnchorId refers to the view that you can swipe and drag.
    motion:touchAnchorSide means that we are dragging the view from the respective side.
    motion:dragDirection refers to the progress direction of the drag. For example, motion:dragDirection="dragUp" means that progress increases as you drag to the up.
  • CustomAttribute: We use this property inside Constraint . This is used to translate the properties those are not related to position or View Attributes like background color, textSize, text color.
<CustomAttribute
motion:attributeName="textColor"
motion:customColorValue="#FFFFFF" />

The other attribute you must provide is based on the value type. Choose from the following supported types:

  • motion:customColorValue for colors
  • motion:customIntegerValue for integers
  • motion:customFloatValue for floats
  • motion:customStringValue for strings
  • motion:customDimension for dimensions
  • motion:customBoolean for booleans

Using Motion layout, you can define all your animation inside MotionScene file and we don’t need to provide any data in class files. It makes it easy to create complex animation.

It has some other Interpolated attributes like scaling, alpha, visibility, elevation, rotation, translation.

Thank you for reading. ? I hope you’ve found this article helpful. If you have any feedback please write me back at karishma.agr1996@gmail.com.Your claps are really appreciated to help others find this article ? .


Motion Layout and Motion Scene was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Karishma Agrawal


Print Share Comment Cite Upload Translate Updates
APA

Karishma Agrawal | Sciencx (2021-04-01T01:38:53+00:00) Motion Layout and Motion Scene. Retrieved from https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/

MLA
" » Motion Layout and Motion Scene." Karishma Agrawal | Sciencx - Thursday April 1, 2021, https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/
HARVARD
Karishma Agrawal | Sciencx Thursday April 1, 2021 » Motion Layout and Motion Scene., viewed ,<https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/>
VANCOUVER
Karishma Agrawal | Sciencx - » Motion Layout and Motion Scene. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/
CHICAGO
" » Motion Layout and Motion Scene." Karishma Agrawal | Sciencx - Accessed . https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/
IEEE
" » Motion Layout and Motion Scene." Karishma Agrawal | Sciencx [Online]. Available: https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/. [Accessed: ]
rf:citation
» Motion Layout and Motion Scene | Karishma Agrawal | Sciencx | https://www.scien.cx/2021/04/01/motion-layout-and-motion-scene/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.