In Android's Vector Drawable documentation, it says the following:
Note: To optimize for the re-drawing performance, one bitmap cache is created for each VectorDrawable. Therefore, referring to the same VectorDrawable means sharing the same bitmap cache. If these references don't agree upon on the same size, the bitmap will be recreated and redrawn every time size is changed. In other words, if a VectorDrawable is used for different sizes, it is more efficient to create multiple VectorDrawables, one for each size.
Does anyone have more details regarding the cashing logic? There can be two ways to change the size of the Vector Drawable which are
- adjusting
widthandheightvalues from the Vector Drawable's XML - adjusting
layout_widthandlayout_heightof the ImageView where the Vector Drawable is provided assrc.
If you were to use the same Vector Drawable in multiple places but by using method 2), what would be the most efficient way to do this? Should I adjust the Vector Drawable height and width to the largest size in use? Will the cached rasterize image be scaled and used where ever the Vector Drawable is used? There isn't much detail in the documentation so I'm bit curious to learn more of how this works and how to use it more efficiently.