Home  >  Q&A  >  body text

Android TextView Html.fromHtml 和使用SpannableString哪一个效率更高

高洛峰高洛峰2720 days ago457

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:55:57

    What is the "efficiency" you want? The total parse time is short? The time until the first screen content is displayed is short (this HTML.fromHTML is not good)? Or something else?


    Is there any other way to make TextView have different display effects (like SpannableString)?

    "Yes", you can always rewrite a set of strings that can express similar semantics and match it with your own TextView.

    But considering that the text that can be displayed simultaneously on a mobile phone is quite limited, I think Spannable (this series is already quite refined) will not become a bottleneck.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:55:57

    If the html content is large and complex, consider using WebView, but you still have to meet actual needs. In terms of efficiency, I think there shouldn't be much difference between the two.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 15:55:57

    Html.fromHtml 适合做一些简单的样式设置,如字体大小,字体颜色。
    但如果涉及到文本的部分可点击,部分字体不同。那就要用到SpannableString.

    reply
    0
  • Cancelreply