首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AnimatedVectorDrawable没有显示任何动画API 21+

AnimatedVectorDrawable没有显示任何动画API 21+
EN

Stack Overflow用户
提问于 2016-12-06 07:13:16
回答 1查看 1.6K关注 0票数 0

我是遵循安卓的指导方针使用动画矢量绘图这里

我使用android vector (img_logo.xml)制作了xml向量文件。

动画矢量可绘制xml文件

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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"/>

我还尝试使用下面显示的这里代码从代码中动画

代码语言:javascript
复制
AnimatedVectorDrawable d = (AnimatedVectorDrawable) getDrawable(R.drawable.anim_logo); // Insert your AnimatedVectorDrawable resource identifier
mImageView.setImageDrawable(d);
d.start();

是动画xml anim_path.xml

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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>

您可以从这里中找到可绘制的向量

我已经设置了一切,如指南中提到的,但当我运行应用程序,它不是动画的形象。任何帮助都很感激。

EN

回答 1

Stack Overflow用户

发布于 2016-12-07 10:27:17

首先,VectorDrawable是相当大和复杂的。这不应该使它停止工作,但可能会导致性能低下;作为参考,文档推荐200 as x 200 as作为最大尺寸

但是,这不是一个工作动画的原因是,AnimatedVectorDrawable试图将VectorDrawable中不存在的部分作为目标。在台词中:

代码语言:javascript
复制
    <target
        android:name="rotationGroup"
        android:animation="@anim/rotate" />
    <target
        android:name="v"
        android:animation="@anim/anim_path" />

目标名称指定要将每个动画应用到VectorDrawable的哪个部分,因此,在VectorDrawable的某个地方,我们希望找到它们:

代码语言:javascript
复制
    <group
        android:name="rotationGroup"
        ...

    <path
        android:name="v"
        ...

但是VectorDrawable中没有与预期目标匹配的部分,所以要想制作一个工作动画,就需要修复它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40989761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档