AnimatedVectorDrawable不设置动画 [英] AnimatedVectorDrawable does not animate

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

问题描述

我试图使动画vectorDrawables正常工作,并根据 http:进行了所有操作: //developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html ,它仍然无法正常工作。

I tried to get animated vectorDrawables working and did everything according to http://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html and it still does not work.

我也试图使该项目正常工作。
https://github.com/chiuki/animated-vector-drawable

I also tried to make this project work. https://github.com/chiuki/animated-vector-drawable

有人知道为什么它没有动画吗?

Does anyone know why it does not animate?

这是我使用的文件:

AnimatedVectorDrawable

<animated-vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/circle">
​
    <target
        android:name="circle"
        android:animation="@anim/morph_to_drop"/>
​
</animated-vector>

VectorDrawable

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="80dp"
        android:height="80dp"
        android:viewportHeight="50"
        android:viewportWidth="50">
​
    <path
        android:name="circle"
        android:fillColor="#607eff"
        android:pathData="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -7.124,16.015 -15.9,16.015c-8.775,0
-15.9,-7.239 -15.9,-16.015c0,-8.775 7.125,-15.9 15.9,-15.9Z"/>
​
</vector>

动画师(morph_to_drop)

Animator (morph_to_drop)

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="1000"
        android:propertyName="pathData"
        android:valueFrom="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -7.124,16.015 -15.9,16.015c-8.775,0
-15.9,-7.239 -15.9,-16.015c0,-8.775 7.125,-15.9 15.9,-15.9Z"
        android:valueTo="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -12.626,30.167
-15.707,30.143c-3.08,-0.024 -16.093,-21.367 -16.093,-30.143c0,-8.775 7.125,-15.9
15.9,-15.9Z"
        android:valueType="pathType"/>
</set>

主布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
​
    <ImageView
        android:id="@+id/testImage"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        android:src="@drawable/circle"/>
​
</RelativeLayout>


推荐答案

尝试以编程方式设置AnimatedVectorDrawable,如下所示:

Try to set the AnimatedVectorDrawable programmatically like this:

AnimatedVectorDrawable d = (AnimatedVectorDrawable) getDrawable(R.drawable.animated_vector); // Insert your AnimatedVectorDrawable resource identifier
mImageView.setImageDrawable(d);
d.start();

这应该可以解决问题。干杯!

This should do the trick. Cheers!

这篇关于AnimatedVectorDrawable不设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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