VectorDrawable
Since Android API 21 (Support Library backports to Android API 7 and above), we can create vector images easily by the VectorDrawable
. Before we dive into animating a VectorDrawable
let's have a deeper understanding of its attributes.
We are going to add a FAB (floating action button) to our DetailActivity.kt
.
And we're also going to add a new vector asset.
With the same way we're also going to add a done icon (✔)
Let's have a look at the pathData attribute. The string contains numbers, which are the coordinates and letters which are the commands. The letters can be either capital, which means that the coordinates are absolute or small, which means that the coordinates are relative
Some of the most used commands are:
M/m --> moveto --> The "moveto" commands establish a new current point. The effect is as if the "pen" were lifted and moved to a new location.
L/l --> lineto --> Draws a line from the current point to the given (x,y) coordinate which becomes the new current point
H/h --> horizontal lineto --> Draws a horizontal line from the current point (cpx, cpy) to (x, cpy)
V/v --> vertical lineto --> Draws a vertical line from the current point (cpx, cpy) to (cpx, y)
C/c --> curveto --> Draws a cubic Bézier curve from one point to a given, using another pair of coordinates as the control point.
Z/z --> closepath --> Close the current subpath by drawing a straight line from the current point to current subpath's initial point. Since the Z and z commands take no parameters, they have an identical effect.
To morph one icon into another, must have the same count of commands as well as the same count of parameters per command.
And finally we export it as animated vector drawable, which we then add to our res>drawable directory.
Last updated