简体   繁体   中英

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?

The short answer is NO.

The linter keep complains for this for the 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 200 dp, but load it and set the size bigger than 200 dp programmatically. It's the same thing. The CPU still needs to doing math to calculate vectors. It still costs a lot depends on how big it was. The vector drawable is ideally for icons, which typically is small.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM