如何重启android AnimatedVectorDrawables动画?

如何重启android AnimatedVectorDrawables动画?,第1张

概述我有一个复杂的矢量drawable,我想动画. 我使用 @RomanNurik’s web工具从svg创建动画 这给了我一个有效的<动画矢量>根据the documentatios.它是一个“一体化”的XML文件. xml的drawable分为2组,每组包含2个路径,并且还添加了4个动画,如下所示: <animated-vector xmlns:android="http://schemas.an 我有一个复杂的矢量drawable,我想动画.
我使用 @RomanNurik’s web工具从svg创建动画

这给了我一个有效的<动画矢量>根据the documentatios.它是一个“一体化”的XML文件.

xml的drawable分为2组,每组包含2个路径,并且还添加了4个动画,如下所示:

<animated-vector xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:aapt="http://schemas.androID.com/aapt">    <aapt:attr name="androID:drawable">        <vector xmlns:androID="http://schemas.androID.com/apk/res/androID"            androID:wIDth="56dp"            androID:height="56dp"            androID:vIEwportHeight="56.0"            androID:vIEwportWIDth="56.0">            <group                androID:name="group_1"                androID:pivotX="25"                androID:pivotY="25">                <path                    androID:name="path_3_1"                    ... />                <path                    androID:name="path"                    ... />            </group>            <group                androID:name="group"                androID:pivotX="25"                androID:pivotY="25">                <path                    androID:name="path_1"                    ... />                <path                    androID:name="path_2"                    ... />            </group>        </vector>    </aapt:attr>    <target androID:name="path">        <aapt:attr name="androID:animation">            <set xmlns:androID="http://schemas.androID.com/apk/res/androID">                <objectAnimator                    androID:name="path"                    ... />                <objectAnimator                    androID:name="path"                  .../>            </set>        </aapt:attr>    </target>    <target androID:name="group_1">        <aapt:attr name="androID:animation">            <set xmlns:androID="http://schemas.androID.com/apk/res/androID">                <objectAnimator                    androID:name="group_1"                    ... />                <objectAnimator                    androID:name="group_1"                    ... />                <objectAnimator                    androID:name="group_1"                    ... />                <objectAnimator                    androID:name="group_1"                    ... />            </set>        </aapt:attr>    </target>    <target androID:name="group">        <aapt:attr name="androID:animation">            <set xmlns:androID="http://schemas.androID.com/apk/res/androID">                <objectAnimator                    androID:name="group"                    ... />                <objectAnimator                    androID:name="group"                    ... />                <objectAnimator                    androID:name="group"                    ... />                <objectAnimator                    androID:name="group"                    ... />            </set>        </aapt:attr>    </target>    <target androID:name="path_3_1">        <aapt:attr name="androID:animation">            <set xmlns:androID="http://schemas.androID.com/apk/res/androID">                <objectAnimator                    androID:name="path_3_1"                    ... />                <objectAnimator                    androID:name="path_3_1"                    ... />            </set>        </aapt:attr>    </target></animated-vector>

问题1:

我不能使用androID:repeatCount =“infinite”,因为ObjectAnimators有不同的androID:duration和androID:startOffset值,这会在一些运行后弄乱动画.所以要走的路是以编程方式重复它.很公平.

问题2:

AnimatedVectorDrawableCompat或AnimatedVectorDrawable都没有一个说动画应该循环的方法.

问题3:

AnimatedVectorDrawableCompat没有registeranimationCallback()所以我可以听onAnimationEnd并自己重启动画.此时,我放弃了逆向兼容性.

问题4:

我使用来自AnimatedVectorDrawable的registeranimationCallback()的当前实现仅适用于androID API 25,即使这些方法是在API 23中添加的

AnimatedVectorDrawable drawable = (AnimatedVectorDrawable) context().getDrawable(R.drawable.long_press_anim);imageVIEw.setimageDrawable(drawable);drawable.registeranimationCallback(new Animatable2.AnimationCallback() {    @OverrIDe    public voID onAnimationEnd(Drawable drawable) {        super.onAnimationEnd(drawable);        ((AnimatedVectorDrawable) drawable).start();    }});drawable.start();

在API 23和24中,动画作为一次性运行,不重复.

任何想法如何解决这个问题?我即将放弃并使用一个狗屎png序列.

解决方法 官方和工作答案在这里: https://issuetracker.google.com/issues/64591234

此代码适用于> = API 16(可能还有14-15).我正在使用支持库26.1.0和vectorDrawables.useSupportlibrary = true(所以我可以引用xml中的vector drawable而不会崩溃)

animatedVector = AnimatedVectorDrawableCompat.create(getContext(),R.drawable.animated_clock);ringingalarmImage.setimageDrawable(animatedVector);final Handler mainHandler = new Handler(Looper.getMainLooper());animatedVector.registeranimationCallback(new Animatable2Compat.AnimationCallback() {    @OverrIDe    public voID onAnimationEnd(final Drawable drawable) {        mainHandler.post(new Runnable() {            @OverrIDe            public voID run() {                animatedVector.start();            }        });    }});animatedVector.start();
总结

以上是内存溢出为你收集整理的如何重启android AnimatedVectorDrawables动画?全部内容,希望文章能够帮你解决如何重启android AnimatedVectorDrawables动画?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1145351.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存