android - AnimatedVectorDrawable 没有动画

标签 android animation android-vectordrawable

我试图让动画 vectorDrawables 工作并根据 http://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html 做了所有事情它仍然不起作用。

我也试图让这个项目成功。 https://github.com/chiuki/animated-vector-drawable

有谁知道为什么它没有动画?

这是我使用的文件:

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)

<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:

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

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

关于android - AnimatedVectorDrawable 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35480074/

相关文章:

android - 尝试将 Firebase 与 AndroidX 一起使用会产生错误 : Failed resolution of: Landroid/support/v4/util/ArrayMap;

matlab - MATLAB 中的动画

Javascript CSS 动画库 Firmin 与 emile

android - 支持库 VectorDrawable Resources$NotFoundException

android - "Hidden due to privacy reasons"在 Google Play 控制台 'App Vitals' 中意味着什么?

java - 如何检查除一个之外的所有数组值是否相同?

android - 矢量可绘制图标的正确尺寸是多少?

android - Android Studio 中未正确绘制矢量可绘制对象

java - 向派生类中的 onClickListener 添加功能

javascript - 向下滑动时旋转图像