android - Android 应用程序应该最大限度地利用 SVG 吗?

标签 android performance user-interface svg

官方文档Vector Asset Studio声明 SVG 可用于减小 APK 大小。它还指出 SVG 需要很多 CPU 周期来绘制。

The initial loading of a vector graphic 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.

此外,从 Lollipop 开始支持它。关于向后兼容性,它指出-

Android 4.4 (API level 20) and lower doesn't support vector drawables. If your minimum API level is set at one of these API levels, you have two options when using Vector Asset Studio: generate Portable Network Graphic (PNG) files (the default) or use the Support Library.

For backward-compatibility, Vector Asset Studio generates raster images of the vector drawable. The vector and raster drawables are packaged together in the APK.

光栅图像看起来比 SVG 更有效。此外,虽然 APK 的大小会减小,但 SVG 对内存和应用程序性能的影响是什么,因为文档指出绘制大型 SVG 文件需要时间。

作为 Android 开发者,我的方法应该是什么?以上哪一种或任何其他方式将确保我的应用得到优化并提供良好的性能。

编辑:然后是一个查询,两者中最好的方法应该是什么 -

  1. 使用 SVG 减小 apk 的大小,但会增加绘图的 CPU 周期
  2. 使用光栅图像

最佳答案

根据我自己的经验,Vector Asset Studio 对于它在 SVG 中接受的内容很挑剔。如果您不精通 SVG,您将很难将 SVG 标记添加到 VAS 接受的内容中。我记得它不支持 defsfilter,但一些矢量图形软件似乎包含它,即使它不是绝对必要的。给定平面图标(例如,没有渐变或阴影),您可以通过手动编辑标记来解决这个问题。

至于性能,这实际上取决于您将在每个屏幕上显示的图标数量,以及这些图标的复杂程度。您将不得不进行一些压力测试,以查看您的目标设备是否经得起考验。请注意,这只会影响初始加载,这些矢量图像在幕后被光栅化,并且如您引用的文本所述:之后,两者之间的内存使用和性能相似

你的方法应该是务实的,试着在屏幕上画几个你的图标,看看它进行得有多顺利。这是一个主观问题,取决于设备的限制和实现它的人。

关于android - Android 应用程序应该最大限度地利用 SVG 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39229245/

相关文章:

android - Android软件包名称Dex问题

android - 哪个是创建 View 的原始线程?

c++ - 与以空结尾的字符串相比,std::string 的效率如何?

performance - 加速用字符串填充单元格的代码

java - 使用 swing 组件在框架中打开文本文件

java - JPanel 将自身绘制在 JFrame 标题栏下方

android - 如何更改 google maps api v2 的自定义信息窗口形状

java - 哪个更快?

wpf - 担心 WPF。我应该为 Windows GUI 使用 WPF 还是其他库?

android - NullPointerException android.support.v7.widget.RecyclerView.onMeasure 的原因