简体   繁体   中英

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. I am using MakeMeAHanzi as the source which can be used to generate animated SVGs for the stroke order animation. One SVG for one Chinese character. 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. I am also getting this error that only occurs when I add in the 9000+ animated vector drawables:

Waited 10 minutes (plus 203200 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@72771445[status=PENDING]

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. 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).

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. The problem was that I was using Inline complex XML resources method to create my AnimatedVectorDrawable. Inside each of my AnimatedVectorDrawable contains multiple VectorDrawables and ObjectAnimators . 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. 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. 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.

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