gpt4 book ai didi

android - 循环动画集会导致 StackOverflowError

转载 作者:行者123 更新时间:2023-12-02 11:12:26 24 4
gpt4 key购买 nike

我正在删除一个 Android 应用程序,其中有一个无限重复的动画,导致 StackOverflowError。当同一对象上的另一个动画开始时,它会执行此操作。

private fun pulse() {
val randomGenerator = Random()

val durationx = randomGenerator.nextInt(4000) + 1500

val inflateX = ObjectAnimator.ofFloat(mContentView, "scaleX", 1.3f).apply {
duration = durationx.toLong()
}
val inflateY = ObjectAnimator.ofFloat(mContentView, "scaleY", 1.3f).apply {
duration = durationx.toLong()
}
val deflateX = ObjectAnimator.ofFloat(mContentView, "scaleX", 1.0f).apply {
duration = durationx.toLong()
}
val deflateY = ObjectAnimator.ofFloat(mContentView, "scaleY", 1.0f).apply {
duration = durationx.toLong()
}
val rotate = ObjectAnimator.ofFloat(mContentView, "rotation", 1.0f).apply {
duration = durationx.toLong()
}
val soulToButton = AnimatorSet().apply {
play(inflateX).with(inflateY)
play(rotate).with(inflateX)
play(deflateX).after(inflateX)
play(deflateY).after(inflateY)
start()
}

soulToButton.addListener(object: AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
soulToButton.start() // stacktrace points to this line as cause for the error.
}
})
soulToButton.start()

AnimatorSet().apply {
play(soulToButton)
start()
}
}

我尝试将函数更改为funpulse(stop: boolean),调用pulse(false)来启动脉冲和pulse(true) code> 在其他动画开始之前,并在多个位置添加 if (stop) {soulToButton.cancel()} 。我还尝试换行导致错误,如下所示: while(stop == false){soultoButton.start()}

所有这些都没有帮助。

最佳答案

试试这个版本:它简短明了,基本上做同样的事情。

    val randomGenerator = Random()

val durationx = randomGenerator.nextInt(4000) + 1500

val animator = animator@{ property : String, value : Float ->
return@animator ObjectAnimator.ofFloat(mContextView, property, value).apply {
duration = durationx.toLong()
repeatMode = REVERSE
repeatCount = INFINITE
}
}

AnimatorSet().apply {
playTogether(animator("scaleX", 1.3f),animator("scaleY", 1.3f),animator("rotation", 45.0f))
start()
}

关于android - 循环动画集会导致 StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54967447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com