Frage

I'm writing an app that constantly updates a TextView with a SpannableStringBuilder that uses a ton of spans. Benchmarking shows that, unsurprisingly, setText() and drawText() are both big blockers, and SpannableStringInternal.getSpans() has the single highest exclusive CPU time.

Is there a way to reuse the same span, so I don't have to clog up my SpannableString with multiple identical spans? Are there other ways I can improve SpannableString performance?

War es hilfreich?

Lösung

After a lot of experimentation, I found that creating a custom View that overrides onDraw to draw its own text is absolutely the way to go here. There's no way to prevent getSpans from using a ton of reflection.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top