0

我正在使用图像跨度来设置按钮的文本,如下所示:

val callback = object : Drawable.Callback {
    override fun unscheduleDrawable(who: Drawable, what: Runnable) {}

    override fun invalidateDrawable(who: Drawable) {
        button.invalidate()
    }

    override fun scheduleDrawable(who: Drawable, what: Runnable, `when`: Long) {}
}
drawable.callback = callback
val drawableSpan = ImageSpan(drawable)
val newText = SpannableString(" ").apply {
    setSpan(drawableSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
button.text = newText

然后稍后将文本更改为简单字符串:

button.text = "Submit"

将文本更改为简单字符串后,我可以假设垃圾收集器会自动清理可绘制对象及其回调对象吗?clearSpans()在设置简单文本之前我还应该打电话吗?

4

0 回答 0