androidlintandroid-vectordrawable

android vector drawable size limit


In my current project, lint complains about a vector drawable that has android:width and android:height set to more than 200 dp. This is explained in:

https://developer.android.com/studio/write/vector-asset-studio

We recommend that you limit a vector image to a maximum of 200 x 200 dp; otherwise, it can take too long to draw.

Does it mean that size of vector drawable in XML file shouldn't exceed this limit, or does it rather mean actual size of drawable on screen ? In other words, if I scale the vector drawable file down so it's width and height are below 200dp each in XML but still use it in same UI element which is bigger than 200x200 dp on screen, is the issue actually solved ?


Solution

  • The short answer is no.

    The linter complains for this reason.

    The initial loading of a vector drawable can cost more CPU cycles than the corresponding raster image. Afterward, memory use and performance are similar between the two. We recommend that you limit a vector image to a maximum of 200 x 200 dp; otherwise, it can take too long to draw.

    So, if you declare both width and height below 200dp, but load it and set the size bigger than 200dp programmatically, it's the same thing. The CPU still needs to do math to calculate the vectors and so it still costs a lot depending on how big the source drawable is. The vector drawable is ideally for icons, which are typically small.

    If you are using a vector drawable bigger than that. You should consider using raster images instead.