android - 使 ObjectAnimator 动画持续时间独立于开发人员选项中的全局动画持续时间比例设置

标签 android animation duration objectanimator animator

当恒定且不可修改的速度至关重要时,如何使 ObjectAnimator 独立于“Animator duration scale”开发人员选项设置?

最佳答案

我注意到没有明确的答案。您可以通过反射调用隐藏的 API 来执行此操作:

// Get duration scale from the global settings.
float durationScale = Settings.Global.getFloat(context.getContentResolver(),
                        Settings.Global.ANIMATOR_DURATION_SCALE, 0);

// If global duration scale is not 1 (default), try to override it
// for the current application.
if (durationScale != 1) {
  try {
    ValueAnimator.class.getMethod("setDurationScale", float.class).invoke(null, 1f);
    durationScale = 1f;
  } catch (Throwable t) {
    // It means something bad happened, and animations are still
    // altered by the global settings. You should warn the user and
    // exit application.
  }
}

有关更多详细信息,您可以查看此博客文章:https://arpytoth.com/2016/12/20/android-objectanimator-independent-of-global-animator-duration/

关于android - 使 ObjectAnimator 动画持续时间独立于开发人员选项中的全局动画持续时间比例设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28516100/

相关文章:

android - 从另一个类开始动画

php - 如何找到每秒的字节数

android - 在 Kotlin 中解析持续时间字符串

java - Google Play 游戏服务解锁成就 - 在游戏中存储解锁或每次调用解锁()?

javascript - 通过 Javascript 更改 Webkit 属性?

android - "If This Then That"如何实现对第三方用户帐户的访问(所谓的 "Channels")?

Android 动画 在 android 2.2 中翻译

performance - 如何查看 Jenkins 任务/构建/项目持续时间的历史图表?

java - 如何在 ListView 中为每个列表项添加三点菜单?

java - 在文本文件android中对数字进行排序