When to use VectorDrawable?

Android Lollipop introduced several new classes, one of which is VectorDrawable. I'm just wondering when it would be convenient to use VectorDrawable over a bitmap, knowing that VectorDrawable has a performance disadvantage. The only thing with VectorDrawable is scalability, which comes at the cost of performance. So when can I use VectorDrawable if performance is a priority? Is the performance too high?

+3


source to share


2 answers


I think that "performance degradation", if present, would be acceptable. Hopefully, you don't create a ton of vector drawings for each frame. Presumably, you will load the VD once, throw it into a drawable, at which point the vector drawable is no longer needed.



Actually the only thing I can see that might be causing the problem is that you are loading an absurd amount of them all at once. But why would you? At this point, just sort of a listing for the sprites.

+2


source


Note that VectorDrawable (versus BitmapDrawable) only has an initial drawing performance overhead. After the first frame of the VectorDrawable appears, the framework will have a cache. From now on, all performance of this VectorDrawable should be the same as BitmapDrawable, if the size has not changed.



VectorDrawable is not recommended for a huge background image like full screen size, but for buttons and icons that are typically less than 200dp x 200dp in size. You should be able to use it without worrying about performance.

+1


source







All Articles