如何根据 Kotlin 中的进度条进度更新 textview 值

How to update textview value based on progressbar progress in Kotlin

我想使用 ObjectAnimatorProgressBar 进度设置动画。但是,我无法更新文本,因为我没有使用 for 循环。使用 ObjectAnimator 时更新 Textview 的最佳方法是什么?这是我尝试更新它但我没有这样做的内容:

val animation = ObjectAnimator.ofInt(progressbar, "progress", 0, 10000)
   animation.setDuration(2000)
   animation.setInterpolator(DecelerateInterpolator())
   animation.start()
   var progress=progressbar.getProgress() /100
   progtxt.text="$progress%"

不确定您能否使用动画执行此操作。

但是你可以使用 SeekBar.OnSeekBarChangeListener

对于 ObjectAnimator,您可以使用更新侦听器:

    animation.addUpdateListener(object: ValueAnimator.AnimatorUpdateListener {
        override fun onAnimationUpdate(animation: ValueAnimator?) {
            val progress = animation?.animatedValue as Int
            // Update you text view
        }
    })

onAnimationUpdate这里,您可以根据需要获取动画值或进度条进度,并将其设置为文本视图。