Spannable VS字样VS的Html [英] Spannable Vs Typeface Vs Html
问题描述
我是preparing的应用程序,其中包含复选框自定义样式如粗体,斜体,下划线,color.etc .. 我有点困惑哪种方法好performance.I试图脸型,但是当用户选择两个复选框,它显示only.it没有工作的最后一个值。
I am preparing app which contains check box for customizing style such as bold,italic,underline,color.etc.. I am little bit confused Which method is good for performance.I have tried type face ,but when user select two check box,it display the last value only.it did not work well.
推荐答案
字样是由涂料对象绘制文本图形元素。它指定的字体(如等宽字体
,无衬线
,细体
等),字体样式(如粗体
,斜体
等),并在内部使用无论 Spannable 和的的HTML 。
Typeface is a graphics element used by Paint object for drawing text. It specifies the font (e.g. Monospace
, Sans Serif
, Serif
, etc.) and the style of font (e.g. Bold
, Italic
, etc.) and is internally used by both Spannable and Html.
这样的表现比较应该与 Spannable
完成和 HTML
。
So the performance comparison should be done between Spannable
and Html
.
Html.fromHtml 是一个昂贵的操作,因为它涉及解析HTML。
我用下面的code与 Traceview 并没有与<对比code> HTML 和 Spannable
。它基本上设置文本加粗并设置超级链接。
Html.fromHtml is a costlier operation as it involves parsing the Html.
I used following code with Traceview and did the comparison between Html
and Spannable
. It basically sets the text bold and sets up the hyperlink.
Debug.startMethodTracing("htmlspan");
Spanned s1 = Html.fromHtml("<b>text1: Constructed from HTML programmatically.</b> Click <a href=\"http://www.google.com\">Link</a> ");
tv1.setText(s1);
Debug.stopMethodTracing();
tv1.setMovementMethod(LinkMovementMethod.getInstance());
Debug.startMethodTracing("normalspan");
SpannableString s2 = new SpannableString("text2: Constructed from JAVA programmatically. Click here.");
s2.setSpan(new StyleSpan(Typeface.BOLD), 0, 45, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
s2.setSpan(new URLSpan("http://www.google.com"),53,53+4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv2.setText(s2);
Debug.stopMethodTracing();
tv2.setMovementMethod(LinkMovementMethod.getInstance());
结果:
- 的HTML API:〜14-15ms (org.ccil.cowan.tagsoup.Parser.parse API前后花了12.282ms)
- Spannbale API:〜1-2MS
- Html API : ~14-15ms. (org.ccil.cowan.tagsoup.Parser.parse API took around 12.282ms)
- Spannbale API : ~1-2ms.
Result:
TraceView的HTML API:
TraceView for Html API:
TraceView为Spannable API:
TraceView for Spannable API:
摘要:视使用性能直接点 Spannable
速度更快相比 HTML
Summary: Performance point of view using directly Spannable
is faster compared to Html
.
这篇关于Spannable VS字样VS的Html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!