gpt4 book ai didi

android - postDelayed 后 View 不能为 null

转载 作者:行者123 更新时间:2023-11-30 05:09:26 25 4
gpt4 key购买 nike

我尝试用 Handler 重复动画任务

   import kotlinx.android.synthetic.main.fragment_main.*
...
...
...
private val mInterval: Long = 3000
private var mHandler: Handler = Handler()
private var mStatusChecker: Runnable = object : Runnable {
override fun run() {
txtUserRole.text = "dddddddddd"
YoYo.with(Techniques.Pulse)
.duration(700)
.playOn(txtUserRole)
mHandler.postDelayed(this, mInterval)
}
}

private fun updateStatus() {

}

fun startRepeatingTask(txtUserRole: TextView) {
mStatusChecker.run()
}

fun stopRepeatingTask() {
mHandler.removeCallbacks(mStatusChecker)
}

在第一次运行时一切正常,但在第一次重复之后 txtUserRoleNULL

最佳答案

最后我尝试在没有处理程序的情况下重复动画

 YoYo.with(Techniques.Pulse)
.duration(700)
.delay(3000)
.withListener(
object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {}
override fun onAnimationEnd(animation: Animator) { animation.start() }
override fun onAnimationCancel(animation: Animator) {}
override fun onAnimationRepeat(animation: Animator) {}
})
.playOn(txtUserRole)

关于android - postDelayed 后 View 不能为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53969554/

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