在包含 HTML 数据的列表中使用 WebView 或 TextView 哪一个?
以性能的名义,最好使用定义了自定义数组适配器的 webview 对象列表或再次使用自定义适配器和 html 内容显示的 textview 对象列表。首先,我尝试使用 webview,但我认为 webview 对象是一种沉重的ui元素,textview看起来更轻量。
WebView entryWebView = (WebView) findViewById(R.id.entryWebView);
entryWebView.loadData("my hmtl formatted data", "text/html", "utf-8");
//假设这些在自定义数组适配器中定义并填充了webview对象
TextView entryTextView = (TextView) v.findViewById(R.id.entry);
entryTextView.setText("my html formatted data");
//并且这又在自定义数组适配器中定义并填充了textview对象
In the name of performance which is better to use list of webview objects with custom array adapter defined or list of textview object again with custom adapter and html content to show in it.First I try to use webview but i think webview object is kind of heavy ui element , textview seems more lightweight.
WebView entryWebView = (WebView) findViewById(R.id.entryWebView);
entryWebView.loadData("my hmtl formatted data", "text/html", "utf-8");
//suppose these defined in custom array adapter and filled with webview objects
TextView entryTextView = (TextView) v.findViewById(R.id.entry);
entryTextView.setText("my html formatted data");
//and this one again in custom array adapter and filled with textview objects
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebView
不能很好地作为ListView
的子级,因为WebView
和ListView
都知道如何滚动。因此,我会使用TextView
。将 HTML 限制为Html.fromHtml()
支持的标记。以下是支持的标签列表从Android 2.1开始,其他版本的Android可能类似。就性能而言,
TextView
确实是一个轻得多的小部件,并且在任何情况下都会表现得更好。不过,您可能希望缓存Html.fromHtml()
输出,这样您就不必在用户滚动时对给定行重新执行此操作。WebView
does not work well as a child ofListView
, since bothWebView
andListView
know how to scroll. Hence, I would useTextView
. Limit your HTML to the tags thatHtml.fromHtml()
supports. Here is a list of supported tags from Android 2.1, and other versions of Android are probably similar.With respect to performance,
TextView
is indeed a significantly lighter widget and would perform better in any case. You may want to cache yourHtml.fromHtml()
output, though, so you do not have to re-do that for a given row as the user scrolls.作为性能比较,我尝试了两者,但是具有大量数据的 WebView 速度慢得令人难以置信,我的自定义适配器甚至无法完成绘制,直到用户响应界面,另一方面 textview 的性能相当不错,我建议使用 textview,除非你需要在文本中做很多 html 工作。
As a perfromance comparison ,I tried both of them but WebView with huge data is incredibily slow , my custom adapter could not even finish drawing until user respond to interface on the other hand textview is doing pretty good as a performance , i recommend using textview unless you need to do lots of html work inside text.