You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Physics-based motion is driven by force. Spring force is one such force that guides interactivity and motion. A spring force has the following properties: damping and stiffness. In a spring-based animation, the value and the velocity are calculated based on the spring force that are applied on each frame.
35
+
36
+
If you'd like your app's animations to slow down in only one direction, consider using a friction-based fling animation instead.
28
37
38
+
### Build a spring animation
39
+
The general steps for building a spring animation for your application are as follows:
29
40
30
-
## Animations
31
-
This section includes different type of animations.
41
+
* Add the support library You must add the support library to your project to use the spring animation classes.
42
+
* Create a spring animation: The primary step is to create an instance of the SpringAnimation class and set the motion behavior parameters.
43
+
* (Optional) Register listeners: Register listeners to watch for animation lifecycle changes and animation value updates.
32
44
33
-
### Physic Base Animations
45
+
**Note:** Update listener should be registered only if you need per-frame update on the animation value changes. An update listener prevents the animation from potentially running on a separate thread.
34
46
47
+
* (Optional) Remove listeners: Remove listeners that are no longer in use.
48
+
* (Optional) Set a start value: Customize the animation start value.
49
+
* (Optional) Set a value range: Set the animation value range to restrain values within the minimum and the maximum range.
50
+
* (Optional) Set start velocity: Set the start velocity for the animation.
51
+
* (Optional) Set spring properties: Set the damping ratio and the stiffness on the spring.
52
+
* (Optional) Create a custom spring: Create a custom spring in case you do not intend to use the default spring or want to use a common spring throughout the animation.
53
+
* Start animation: Start the spring animation.
54
+
* (Optional) Cancel animation: Cancel the animation in case the user abruptly exits the app or the view becomes invisble.
35
55
36
56
## Drawable Animations
37
57
@@ -59,20 +79,24 @@ A VectorDrawable can be represented in xml with
59
79
60
80
where width and height are the actual dimensions of while viewportWidth, and viewportHeight are used for drawing coordinates.
61
81
62
-
**M** represents move to a coordinate
63
-
**L** means draw a line from previous coordinate to coordinates after *L*
64
-
**C** is contour
65
-
**Z** closes/ends the drawing shape
82
+
**M**(x,y) Begin a new subpath by moving to (x,y).
66
83
67
-
**<group>** tag is used for grouping sections of drawable to be able to be animated together. And some animations such as
84
+
**L**(x,y) Draw a line to (x,y).
85
+
86
+
**C** (x1,y1 x2,y2 x,y) Draw a cubic bezier curve to (x,y) using control points (x1,y1) and (x2,y2).
87
+
88
+
**Z** Close the path by drawing a line back to the beginning of the current subpath
89
+
90
+
**'<group>'** tag is used for grouping sections of drawable to be able to be animated together. And some animations such as
68
91
rotation, and translation can only be applied to groups.
69
92
70
93
Animations can be performed on the animatable attributes in android.graphics.drawable.VectorDrawable.
71
94
These attributes will be animated by android.animation.ObjectAnimator.
72
95
The ObjectAnimator's target can be the root element, a group element or a path element.
73
96
The targeted elements need to be named uniquely within the same VectorDrawable.
74
97
Elements without animation do not need to be named.
75
-
98
+
99
+
For more details you check out [here](https://www.androiddesignpatterns.com/2016/11/introduction-to-icon-animation-techniques.html)
76
100
77
101
### XML for AnimatedVectorDrawable
78
102
An AnimatedVectorDrawable element has a VectorDrawable attribute, and one or more target element(s).
Copy file name to clipboardExpand all lines: Tutorial2-1AnimatedVectorDrawables/src/main/java/com/smarttoolfactory/tutorial2_1animatedvectordrawables/Activity1_1Basics.kt
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -97,11 +97,18 @@ class Activity1_1Basics : AppCompatActivity() {
0 commit comments