简体   繁体   English

AnimatedVectorDrawable - reset() 在某些华为设备上无法正常工作

[英]AnimatedVectorDrawable - reset() is not working properly on some Huawei devices

We use AnimatedVectorDrawable.reset() to reset the animation to its initial state.我们使用AnimatedVectorDrawable.reset()将动画重置为其初始状态。 This works well on most of the devices.这适用于大多数设备。 While testing we noticed that on some Huawei devices when reset() is called the animation starts running.在测试时我们注意到在一些华为设备上调用reset()时动画开始运行。

Reproduced on these Huawei devices:在这些华为设备上转载:

  • ANE-LX1 - Android 8.0.0, EMIU 8.0.0 ANE-LX1 - 安卓 8.0.0,EMIU 8.0.0
  • LYA-L29 - Android 10, EMIU 10.0.0 LYA-L29 - Android 10,EMIU 10.0.0

Any ideas what can I do to fix the problem?任何想法我能做些什么来解决这个问题?

To fix the problem I updated the animation to end in the state it starts.为了解决这个问题,我更新了动画以在它开始的状态下结束。 This allowed me to stop using AnimatedVectorDrawable.reset() .这让我可以停止使用AnimatedVectorDrawable.reset()

Section "Stale state" from this article helped me resolve the problem.从部分“陈旧状态” 这篇文章帮我解决这个问题。 Here is the important part of the section:这是该部分的重要部分:

On older devices I found that their 'state' wasn't being reset (to how it was defined in the VectorDrawable) on each loop.在较旧的设备上,我发现它们的“状态”在每个循环中都没有被重置(在 VectorDrawable 中是如何定义的)。 ... To fix this I added a zero length animation to set properties to their expected value at the start of each loop so that they're ready to be animated eg: ...为了解决这个问题,我添加了一个零长度动画,以便在每个循环开始时将属性设置为其预期值,以便它们准备好进行动画处理,例如:

<set>
    <objectAnimator
        android:propertyName="fillAlpha"
        android:valueFrom="0"
        android:valueTo="0"
        android:duration="0" />
    <objectAnimator
        android:propertyName="fillAlpha"
        android:valueFrom="0"
        android:valueTo="1"
        android:startOffset="1900"
        android:duration="60"
        android:interpolator="@android:interpolator/linear" />
</set>

This is the part that resets the animation to its initial state:这是将动画重置为其初始状态的部分:

    <objectAnimator
        android:propertyName="fillAlpha"
        android:valueFrom="0"
        android:valueTo="0"
        android:duration="0" />

valueFrom and valueTo are equal to valueFrom in the second objectAnimator . valueFromvalueTo等于valueFrom在第二objectAnimator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AutoCompleteTextView在华为设备中不起作用 - AutoCompleteTextView not working in Huawei devices 活动在某些设备上无法正常工作 - Activities not working properly in some devices 动画在某些设备上无法正常工作-Android - Animation is not working properly on some devices - android Android相机意图在某些设备上无法正常工作 - android camera intent not working properly on some devices Edittext背景在某些设备中无法正常工作 - Edittext background not working properly in some devices Firebase 推送通知在某些设备上无法正常工作 - Firebase push notifications not working properly in some devices 运行时本地化(多语言)在某些设备上不起作用,例如。 Oppo F9和华为Y9 - RunTime Localization (Multi-language) not working on some devices ex. Oppo f9 and Huawei y9 前台服务和 WakeLocks 不适用于华为设备 - Foreground Service and WakeLocks are not working on Huawei Devices BOOT_COMPLETED 不适用于华为设备 - BOOT_COMPLETED not working on Huawei devices 小部件固定不适用于 Android 华为和 Vivo 设备 - Widget pinning not working with Android Huawei and Vivo devices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM