简体   繁体   English

如何处理大量动画矢量绘图?

[英]How to handle large amount of animated vector drawables?

I am making a Chinese dictionary app that can show users the Chinese characters stroke order animation.我正在制作一个中文字典应用程序,可以向用户显示汉字笔顺 animation。 I am using MakeMeAHanzi as the source which can be used to generate animated SVGs for the stroke order animation.我使用MakeMeAHanzi作为源,可用于为笔画顺序 animation 生成动画 SVG。 One SVG for one Chinese character.一个汉字一个 SVG。 Using the same concept, I generated animated vector drawables instead.使用相同的概念,我生成了动画矢量可绘制对象。

Currently my android app contains 9000+ animated vector drawables and it is taking a long time to build.目前我的 android 应用程序包含 9000 多个动画矢量可绘制对象,并且构建需要很长时间。 I am also getting this error that only occurs when I add in the 9000+ animated vector drawables:我也收到此错误,仅当我添加 9000 多个动画矢量可绘制对象时才会出现:

Waited 10 minutes (plus 203200 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@72771445[status=PENDING]等待 com.google.common.util.concurrent.SettableFuture@72771445[status=PENDING] 10 分钟(加上 203200 纳秒延迟)

I've considered using GIFs and load it from the expansion file instead but I would really like to have the advantage of resolution-independence.我考虑过使用 GIF 并从扩展文件中加载它,但我真的很想拥有独立于分辨率的优势。 I've tried loading the animated vector drawables from the expansion file but it seems that I can't load.xml from the file system as drawables unless I precompile it as binary XML and I think this will be my last resort as I am still not sure how to achieve this yet since I am unable to build the APK (I can extract precompiled binary XML from the APK).我已经尝试从扩展文件中加载动画矢量drawables,但似乎我无法从文件系统加载.xml 作为drawables,除非我将它预编译为二进制XML,我认为这将是我最后的手段,因为我仍然不知道如何实现这一点,因为我无法构建 APK(我可以从 APK 中提取预编译的二进制 XML)。

May I know if there are more efficient ways of handling large amount of vector drawables or other alternatives to handling this situation?我可以知道是否有更有效的方法来处理大量矢量绘图或其他替代方法来处理这种情况? Thank you.谢谢你。

I've managed to solve the long compilation time problem and just in case anyone might stumble upon this post, I'll post my solution here.我已经设法解决了编译时间长的问题,以防万一有人偶然发现这篇文章,我将在这里发布我的解决方案。

Apparently, 9000+ AnimatedVectorDrawable wasn't the problem.显然,9000+ AnimatedVectorDrawable不是问题。 The problem was that I was using Inline complex XML resources method to create my AnimatedVectorDrawable.问题是我使用内联复杂 XML 资源方法来创建我的 AnimatedVectorDrawable。 Inside each of my AnimatedVectorDrawable contains multiple VectorDrawables and ObjectAnimators .在我的每个 AnimatedVectorDrawable 内部都包含多个VectorDrawablesObjectAnimators This means that even if there is only 1 AnimatedVectorDrawable XML file, the AAPT tool will create multiple XMLs for the VectorDrawables and ObjectAnimators which also means that I ended up with way more than 9000+ AnimatedVectorDrawables.这意味着即使只有 1 个 AnimatedVectorDrawable XML 文件,AAPT 工具也会为 VectorDrawables 和 ObjectAnimators 创建多个 XML,这也意味着我最终得到了超过 9000 多个 AnimatedVectorDrawables。 This was the cause of the long compilation time.这就是编译时间长的原因。

So, I ended up creating VectorDrawables instead and created a Class to handle the ObjectAnimators at runtime.因此,我最终创建了 VectorDrawables,并创建了一个 Class 来在运行时处理 ObjectAnimators。 However, to achieve this, I had to use Java reflection techniques to access the private getTargetByName function in VectorDrawable to get the Target object for the ObjectAnimators and use the invalidateSelf function of the VectorDrawable in a Thread to update the VectorDrawable at runtime. However, to achieve this, I had to use Java reflection techniques to access the private getTargetByName function in VectorDrawable to get the Target object for the ObjectAnimators and use the invalidateSelf function of the VectorDrawable in a Thread to update the VectorDrawable at runtime.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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