内容简介:翻译自:https://stackoverflow.com/questions/27626831/error-while-trying-to-test-animatedvectordrawable-cant-morph-from-x-to-z
一样神奇,有动画和东西.
我找到了 this great tutorial ,关于如何使用&实现它们等,后来我发现 a very usefull tool 将SVG转换为Android-VectorDrawables,并转换了这两个图像:
https://github.com/google/material-design-icons/blob/master/content/svg/design/ic_add_48px.svg
https://github.com/google/material-design-icons/blob/master/action/svg/design/ic_done_48px.svg现在这是我提出的xml-“代码”:
绘制/ vector_add.xml:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group>
<path
android:pathData="M0 0h48v48h-48Z" />
<path
android:name="add"
android:fillColor="#ffffff"
android:pathData="M38 26h-12v12h-4v-12h-12v-4h12v-12h4v12h12v7Z" />
</group>
</vector>
动画/ add_to_done.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="3000"
android:propertyName="pathData"
android:valueFrom="M38 26h-12v12h-4v-12h-12v-4h12v-12h4v12h12v7Z"
android:valueTo="M18 32.34l-8.34-8.34-2.83 2.83 11.17 11.17 24-24-2.83-2.83Z"
android:valueType="pathType" />
</set>
绘制/ ic_add.xml:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_add">
<target
android:name="add"
android:animation="@anim/anim_plus_to_done" />
</animated-vector>
如果我运行此代码,我最终会遇到此错误:
Caused by: android.view.InflateException: Binary XML file line #3 Can't morph from M38 26h-12v12h-4v-12h-12v-4h12v-12h4v12h12v4Z to M18 32.34l-8.34-8.34-2.83 2.83 11.17 11.17 24-24-2.83-2.83Z
at android.animation.AnimatorInflater.setupAnimatorForPath(AnimatorInflater.java:337)
at android.animation.AnimatorInflater.parseAnimatorFromTypeArray(AnimatorInflater.java:283)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:618)
at android.animation.AnimatorInflater.loadObjectAnimator(AnimatorInflater.java:577)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:529)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:542
我的猜测是两个svg中的两个路径太不同了,所以Android无法自己处理动画,我需要为每个动画“checkpoint”制作几个VectorDrawables.
……我可能完全偏离这个理论,但这是我能想到的最合乎逻辑的……
我没有太多经验(也没有任何经验)与Vector&插画家等,所以你们提出的任何帮助将非常感激.
祝你今天愉快,
和圣诞快乐.
此致
芒.
你想要变形的VectorDrawables必须是兼容的,这意味着它们必须具有类似的复杂性;类似的长度和命令数(pksink提到了这一点).
这样我最终解决这个问题就是采用“加号”符号并在android studio中手动修改尺寸,直到我得到一个类似于复选标记的东西.
加上矢量:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
android:height="24dp">
<group android:name="plus_group" android:pivotX="12" android:pivotY="12">
<path
android:name="plus_path"
android:strokeColor="@android:color/white"
android:strokeWidth="3"
android:pathData="M12,0L12,24M0,12,L24,12" />
</group>
</vector>
CheckMark矢量:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="24"
android:viewportHeight="24"
android:width="24dp"
android:height="24dp">
<group android:name="check_group"
android:pivotX="12"
android:translateX="0"
android:pivotY="12">
<path
android:name="check_path"
android:strokeColor="@android:color/white"
android:strokeWidth="3"
android:pathData="M20,0L06,20M0,14,L08,19" />
</group>
</vector>
请注意,这些命令的数量相同.选中标记看起来并不完美,但如果将其放在浮动操作按钮中,则无法注意到.
附加提示:将pathData移动到字符串变量.这样,在objectAnimators中保持一致性就更容易了.
翻译自:https://stackoverflow.com/questions/27626831/error-while-trying-to-test-animatedvectordrawable-cant-morph-from-x-to-z
以上所述就是小编给大家介绍的《android – 尝试测试AnimatedVectorDrawable时出错,“无法从x变换为z”》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- WebGL 入门与实践 --- 坐标系变换 :基本变换原理与算法实现
- 如何避免空指针出错?
- 如何避免特效渲染出错?
- OmniROM:“Flex checkpolicy”出错
- Python安装软件包出错
- 图像变换函数
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Pro JavaScript Techniques
John Resig / Apress / 2006-12-13 / USD 44.99
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web s......一起来看看 《Pro JavaScript Techniques》 这本书的介绍吧!