Java 支持库中的AnimatedVectorDrawable和动画;“路径数据”;
我正在使用支持库23.2.0中的动画向量,如下所示:Java 支持库中的AnimatedVectorDrawable和动画;“路径数据”;,java,android,android-animation,android-support-library,android-vectordrawable,Java,Android,Android Animation,Android Support Library,Android Vectordrawable,我正在使用支持库23.2.0中的动画向量,如下所示: compile 'com.android.support:support-vector-drawable:23.2.0' compile 'com.android.support:animated-vector-drawable:23.2.0' 我正在尝试设置“pathData”的动画(使线彼此变形)。我的代码看起来像这样 可绘制/ic_done.xml: <?xml version="1.0" encoding="utf-8"?&g
compile 'com.android.support:support-vector-drawable:23.2.0'
compile 'com.android.support:animated-vector-drawable:23.2.0'
我正在尝试设置“pathData”的动画(使线彼此变形)。我的代码看起来像这样
可绘制/ic_done.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:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:name="tick"
android:pathData="M4.8,12L9,16.2L20,8"
android:strokeColor="#FF000000" />
</vector>
它在API级别为21的较新设备上运行良好,但在API级别为16的设备上有一个问题:
java.lang.NumberFormatException: Invalid int: "M4.8,12L4.8,12L4.8,12"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:258)
at android.animation.AnimatorInflater.loadObjectAnimator(AnimatorInflater.java:161)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:117)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:126)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:93)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:72)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:377)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.create(AnimatedVectorDrawableCompat.java:142)
根据一篇文章,动画向量(AnimatedVectorDrawableCompat)应该支持回到API级别11
从勾选路径动画.xml读取值from属性时似乎失败。此属性类型“pathType”可能不受支持(尚未支持)。你知道如何解决这个问题吗?很抱歉,当前版本的支持库(23.2.0)无法解决这个问题 看 在
弗兰克的评论:
这最终在支持lib25.4.0(2017年6月)中得到了修复:“路径 中支持变形和路径插值 动画矢量DrawableCompat“
上述动画(图像中心)中的圆形“闪光”是我按下屏幕开始变形。
充气牵引式 此支持库(`vector compat`)中的
`VectorDrawable`
和`AnimatedVectorDrawable`
可以通过以下方式膨胀:
- 调用static
方法:getDrawable()
矢量兼容,此处:
如果将问题与应用程序模块的build.gradle
依赖项(通常在文件末尾)合并,这将解决问题(一直到API 14
):
非常感谢,我无法找到这些限制。@Lewis McGeary:您是否发现支持Path24.2.0的版本在24.2.0中仍然不起作用的任何信息。这使得支持库的整个“Compat”部分对我来说毫无用处!在声明API11的兼容性后,这很烦人,但是隐藏了不起作用的“相关”细节。应称为AnimatedVectorDrawablePartiallyCompat..这是因为支持库当前依赖于框架的AnimatorInFalter来获取向量drawables,并且仅在API 21中添加了为objectAnimator声明除intType或floatType之外的valueType的功能。在这方面,甚至有关动画资源的文档也不是最新的。这最终在support lib 25.4.0(2017年6月)中得到了修复:“AnimatedVectorDrawableCompat支持路径变形和路径插值”尝试使用wnafee提供的向量Compat,我已经测试了路径变形,很好您的问题在support lib 25.4.0+中得到了解决:对于平台<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<objectAnimator
android:duration="200"
android:propertyName="pathData"
android:valueFrom="M4.8,12L4.8,12L4.8,12"
android:valueTo="M4.8,12L9,16.2L9,16.2"
android:valueType="pathType" />
<objectAnimator
android:duration="200"
android:propertyName="pathData"
android:valueFrom="M4.8,12L9,16.2L9,16.2"
android:valueTo="M4.8,12L9,16.2L20,8"
android:valueType="pathType" />
</set>
ImageView vImgAnimated = findByViewId(R.id.img);
AnimatedVectorDrawableCompat animatedVector = AnimatedVectorDrawableCompat.create(getContext(), R.drawable.ic_done_animated);
vImgAnimated.setImageDrawable(animatedVector);
animatedVector.start();
java.lang.NumberFormatException: Invalid int: "M4.8,12L4.8,12L4.8,12"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:258)
at android.animation.AnimatorInflater.loadObjectAnimator(AnimatorInflater.java:161)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:117)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:126)
at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:93)
at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:72)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.inflate(AnimatedVectorDrawableCompat.java:377)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.createFromXmlInner(AnimatedVectorDrawableCompat.java:162)
at android.support.graphics.drawable.AnimatedVectorDrawableCompat.create(AnimatedVectorDrawableCompat.java:142)
//This will only inflate a drawable with <vector> as the root element
VectorDrawable.getDrawable(context, R.drawable.ic_arrow_vector);
//This will only inflate a drawable with <animated-vector> as the root element
AnimatedVectorDrawable.getDrawable(context, R.drawable.ic_arrow_to_menu_animated_vector);
// This will inflate any drawable and will auto-fallback to the lollipop implementation on api 21+ devices
ResourcesCompat.getDrawable(context, R.drawable.any_drawable);
import com.wnafee.vector.compat.AnimatedVectorDrawable;
mdrawable = (AnimatedVectorDrawable) AnimatedVectorDrawable.getDrawable(this.getApplicationContext(), R.drawable.consolidated_animated_vector);
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Trying to FIX Binary XML file line #2: invalid drawable tag animated-vector
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
//not needed
// compile 'com.android.support:support-vector-drawable:25.0.0'
compile 'com.wnafee:vector-compat:1.0.5'//*******holy grail *******https://github.com/wnafee/vector-compat
// Failed to resolve: com.android.support:support-animated-vector-drawable:25.0.0
//not needed
// compile 'com.android.support:support-animated-vector-drawable:25.0.0'
}