Animated Vector Drawable Animation does not work

≯℡__Kan透↙ 提交于 2021-01-29 04:42:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41822179/animated-vector-drawable-animation-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!