Search code examples
androidanimationandroid-animationandroid-vectordrawable

Animated Vector Drawable Animation does not work


I can't figure out why my Animated Vector is not working. I can see the first path but the second path that I want to animate as an addition to the first path is not showing. This is how my code looks like:

<?xml version="1.0" encoding="utf-8"?>
<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="24dp"
            android:width="24dp"
            android:viewportHeight="24.0"
            android:viewportWidth="24.0" >

            <path
                android:name="v"
                android:strokeColor="#000000"
                android:strokeWidth="3"
                android:pathData="M6,11 l3.5, 4 l0, 0" />
        </vector>
    </aapt:attr>

    <target android:name="v" >
        <aapt:attr name="android:animation">
            <set>
                <objectAnimator
                    android:duration="1000"
                    android:propertyName="pathData"
                    android:valueFrom="M6,11 l3.5, 4 l0, 0"
                    android:valueTo="M6,11 l3.5, 4 l8, -7"
                    android:valueType="pathType"/>
            </set>
        </aapt:attr>
    </target>
</animated-vector>

So, M6,11 l3.5, 4 l0, 0 is showing on the screen but not M6,11 l3.5, 4 l8, -7

I tried copy the example from the bottom of the google docs here and that did work. My file animated correctly if I use their code which tells me I do start the animation correctly. Is this a typo or something wrong with my path data?


Solution

  • I tested my drawable in a new project and to my surprise it was working fine.

    I was using com.android.support:design:25.1.0 in my first project and it turns out degrading to com.android.support:design:24.2.0 made it work.

    After testing a bit more I found that changing from app:srcCompat="@drawable/animated_vector" to android:src="@drawable/animated_vector" on my ImageView made it work for com.android.support:design:25.1.0 as well.

    Im not sure whats going on but now it works at least. If someone has more details on this please let me know. I thought we where supposed use srcCompat for vector drawables.