【发布时间】:2020-10-06 12:47:30
【问题描述】:
我的应用严重依赖动画来工作,当开发者的选项中改变它们的速度时,整个应用会中断并停止工作。我一直在研究忽略开发人员设置并强制动画按应有方式运行的方法,但它并没有真正改变任何东西。
我在我的应用程序类中调用这个函数onCreate:
private fun fixAnimation() {
val durationScale = Settings.Global.getFloat(contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f)
Log.d("fixAnimation", "durationScale: $durationScale")
if (durationScale != 1f) {
try {
ValueAnimator::class.java.getMethod("setDurationScale",Float::class.javaPrimitiveType).invoke(null, 1f)
} catch (t: Throwable) {
Log.e("fixAnimation", t.message ?: t.toString())
}
}
}
但什么都没有改变。
从这里得到它:Make ObjectAnimator animation duration independent of global animator duration scale setting in developer options 在这里:https://medium.com/@arpytoth/android-objectanimator-independent-of-global-animator-duration-fe33c808c83e 显然它适用于某些人,但不适用于我的情况。
可能是因为我使用的是 ViewPropertyAnimator,而不是直接使用 ValueAnimator?但它应该仍然有效,因为这会全局更改 ValueAnimator 的持续时间比例设置,并且 ViewPropertyAnimator 由 ValueAnimator 支持...
【问题讨论】:
标签: android kotlin reflection android-animation android-reflection