在包含 HTML 数据的列表中使用 WebView 或 TextView 哪一个?

发布于 2024-10-08 17:46:31 字数 555 浏览 0 评论 0原文

以性能的名义,最好使用定义了自定义数组适配器的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当爱已成负担 2024-10-15 17:46:31

WebView 不能很好地作为 ListView 的子级,因为 WebViewListView 都知道如何滚动。因此,我会使用 TextView。将 HTML 限制为 Html.fromHtml() 支持的标记。以下是支持的标签列表从Android 2.1开始,其他版本的Android可能类似。

就性能而言,TextView 确实是一个轻得多的小部件,并且在任何情况下都会表现得更好。不过,您可能希望缓存 Html.fromHtml() 输出,这样您就不必在用户滚动时对给定行重新执行此操作。

WebView does not work well as a child of ListView, since both WebView and ListView know how to scroll. Hence, I would use TextView. Limit your HTML to the tags that Html.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 your Html.fromHtml() output, though, so you do not have to re-do that for a given row as the user scrolls.

℡寂寞咖啡 2024-10-15 17:46:31

作为性能比较,我尝试了两者,但是具有大量数据的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文