我是遵循安卓的指导方针使用动画矢量绘图这里。
我使用android vector (img_logo.xml)制作了xml向量文件。
动画矢量可绘制xml文件
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_logo" >
<target
android:name="rotationGroup"
android:animation="@anim/rotate" />
<target
android:name="v"
android:animation="@anim/anim_path" />
</animated-vector>并将其设置为imageview
<ImageView
android:id="@+id/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="@dimen/view_elevation"
android:layout_marginBottom="@dimen/activity_horizontal_margin"/>我还尝试使用下面显示的这里代码从代码中动画
AnimatedVectorDrawable d = (AnimatedVectorDrawable) getDrawable(R.drawable.anim_logo); // Insert your AnimatedVectorDrawable resource identifier
mImageView.setImageDrawable(d);
d.start();是动画xml anim_path.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="1000"
android:propertyName="pathData"
android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z"
android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z"
android:valueType="pathType" />
</set>rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="1000"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="360" />
</set>您可以从这里中找到可绘制的向量
我已经设置了一切,如指南中提到的,但当我运行应用程序,它不是动画的形象。任何帮助都很感激。
发布于 2016-12-07 10:27:17
首先,VectorDrawable是相当大和复杂的。这不应该使它停止工作,但可能会导致性能低下;作为参考,文档推荐200 as x 200 as作为最大尺寸。
但是,这不是一个工作动画的原因是,AnimatedVectorDrawable试图将VectorDrawable中不存在的部分作为目标。在台词中:
<target
android:name="rotationGroup"
android:animation="@anim/rotate" />
<target
android:name="v"
android:animation="@anim/anim_path" />目标名称指定要将每个动画应用到VectorDrawable的哪个部分,因此,在VectorDrawable的某个地方,我们希望找到它们:
<group
android:name="rotationGroup"
...
<path
android:name="v"
...但是VectorDrawable中没有与预期目标匹配的部分,所以要想制作一个工作动画,就需要修复它。
https://stackoverflow.com/questions/40989761
复制相似问题