动画矢量可绘制动画不起作用 [英] Animated Vector Drawable Animation does not work

查看:78
本文介绍了动画矢量可绘制动画不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我的动画矢量无法正常工作.我可以看到第一个路径,但是没有显示要动画化的第二个路径.这是我的代码的样子:

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>

因此,屏幕上显示 M6,11 l3.5,4 l0,0 ,而不显示 M6,11 l3.5,4 l8,-7

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

我尝试从google文档的底部复制示例(此处),它确实起作用.如果我使用他们的代码,可以告诉我确实正确启动了动画,则文件可以正确设置动画.这是输入错误还是我的路径数据有问题?

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?

推荐答案

我在一个新项目中测试了我的可绘制对象,令我惊讶的是它运行良好.

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

我在我的第一个项目中使用了 com.android.support:design:25.1.0 ,结果降级为 com.android.support:design:24.2.0 使其工作.

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.

经过更多测试后,我发现我的应用程序从 app:srcCompat ="@ drawable/animated_vector" 更改为 android:src ="@ drawable/animated_vector" ImageView 使其也适用于 com.android.support:design:25.1.0 .

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.

我不确定发生了什么,但现在至少可以了.如果有人对此有更多详细信息,请告诉我.我以为我们应该在矢量可绘制对象中使用 srcCompat .

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.

这篇关于动画矢量可绘制动画不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆