Share My Creation (b4a) AnimatedVectorDrawable

To show AnimatedVectorDrawable we need 3 XML components:
  1. VectorDrawable (.xml) - The static vector shapes
  2. ObjectAnimator (.xml) - The animation definitions
  3. AnimatedVectorDrawable (.xml) - Connects vectors with animations
A barebone working B4A code with all three XML components is on Github: https://github.com/jkhazraji/AnimatedVectorDrawable-inb4a . It depicts an analog clock that starts at12:00. Any AnimatedVectorDrawable bundle that complies with the above scheme can be shown with it. However, the AAPT tool supports a new Android format that bundles several related XML files together, we can merge the XML files from this example into one XML file. XML files can be created from scratch or generated in manifest file.
A demo video captured from an emulator shows an animated vector drawable. It is neither gif nor any other animated format:



Try this new format xml file:
XML:
 <animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:aapt="http://schemas.android.com/aapt" >
     <aapt:attr name="android:drawable">
         <vector
             android:height="64dp"
             android:width="64dp"
             android:viewportHeight="600"
             android:viewportWidth="600" >
             <group
                 android:name="rotationGroup"
                 android:pivotX="300.0"
                 android:pivotY="300.0"
                 android:rotation="45.0" >
                 <path
                     android:name="v"
                     android:fillColor="#000000"
                     android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
             </group>
         </vector>
     </aapt:attr>

     <target android:name="rotationGroup"> *
         <aapt:attr name="android:animation">
             <objectAnimator
             android:duration="6000"
             android:propertyName="rotation"
             android:valueFrom="0"
             android:valueTo="360" />
         </aapt:attr>
     </target>

     <target android:name="v" >
         <aapt:attr name="android:animation">
             <set>
                 <objectAnimator
                     android:duration="3000"
                     android:propertyName="pathData"
                     android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z"
                     android:valueTo="M300,70 l 0,-70 70,0  0,140 -70,0 z"
                     android:valueType="pathType"/>
             </set>
         </aapt:attr>
      </target>
 </animated-vector>

Note: comma in manifest file should be escaped (https://www.b4x.com/android/forum/t...manifest-script-createresource.99783/#content)
If you like donate to get the clock xml files and see how it works.
 

jkhazraji

Active Member
Licensed User
Longtime User
Looks good, congratulation for effort.

What are benefit over gif/apng , other than smaller size ?
What extra jar/libraries will be required ?
Thanks for your words. These are xml text files that can be customized for different needs and settings. They are resolution-independent and can be scaled infinitely. Their colors can be changed as well as type of animation. In GIF/APNG, they have to be re-created or updated as they are binary format. Any Android interpolator can be used for their animation and I think they are more memory-effecient.
No need for extra jar files or libraries as they are in the core Android library and dealt with as resources that can be embedded in any relevant view.
 

jkhazraji

Active Member
Licensed User
Longtime User
Here is another one taken from the Github : https://github.com/chiuki/animated-vector-drawable.

face-ezgif.com-optimize.gif
 
Top