How to animate a VectorDrawable in a fluid-like manner?

情到浓时终转凉″ 提交于 2019-12-05 08:16:55

There are a few ways to get a similar look, however not all are going to be backwards compatible using the support library. For that reason I'd recommend using trimPathStart and trimPathEnd.

I'll describe the approach I would take, rather than the final solution(can be time consuming!).

The first problem in getting started is that your original VectorDrawable isn't really suitable for this type of animation!

The drawable in the question describes the outline of the shape(ie. the nine lines outlining the arrow) and displays the fill. What would be better for our purposes would be to have a drawable made up of three lines where there is no fillColor and instead we set how the lines should display using strokeColor and strokeWidth.

This should be a simple VectorDrawable with three <path> elements: one for the vertical line, and one each for the sides of the arrow head.

Once you have this you can think about how you want your animation to look. trimPathStart and trimPathEnd should be values between 0 and 1 where 0 is the start of the path and 1 is the end. Consider the vertical line drawn from top to bottom:

trimPathStart="0" trimPathEnd="0" --we can't see the line

-> animate to

trimPathStart="0" trimPathEnd="1" --we've drawn the line from top to bottom

-> animate to

trimPathStart="1" trimPathEnd="1" --we've made the line disappear again by moving the starting point from top to bottom

You would do a similar thing with each side of the arrow and order things as appropriate to get your desired effect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!