postDelayed 后视图不能为 null
view must not be null after postDelayed
我尝试用 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)
}
首先 运行 一切正常,但在第一次重复 txtUserRole 之后是 NULL
最后我尝试在没有处理程序的情况下重复动画
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)
我尝试用 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)
}
首先 运行 一切正常,但在第一次重复 txtUserRole 之后是 NULL
最后我尝试在没有处理程序的情况下重复动画
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)