Android:加快(html 格式)文本的显示

标签 android html textview stringbuilder scrollview

我的应用程序使用 StringBuilder 组合文本段落,然后显示在 ScrollView 内的 TextView 中。

displaytext.xml 布局文件是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:id="@+id/ScrollView01"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
>
  <TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/display_text" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      >
  </TextView>
</ScrollView>   
</LinearLayout>

显示StringBuilder对象sbText的代码是

    setContentView(R.layout.displaytext);
    TextView tv = (TextView)findViewById(R.id.display_text);
    tv.setText(Html.fromHtml(sbText.toString()));

这工作正常,除了随着文本量的增加它变得非常慢。例如,要显示 50 个段落,总共约 50KB 的文本,仅执行这三行代码就需要 5 秒以上。

有人可以建议我如何加快速度吗?

最佳答案

Can anyone suggest how I can speed this up, please?

使用 WebView 而不是 ScrollViewTextView

此外,正如 Nick 所指出的,通过使用 Traceview 或其他工具,确认您所花的时间确实花在了您认为的地方。

关于Android:加快(html 格式)文本的显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4618605/

相关文章:

android - 两行文本换行 - recyclerview

java - 容器无法解析或不是字段

Android:在循环中使用带有字符串的 findViewById()

python - 获取for循环中的项目总数

html - 我无法更改 html 中的段落颜色

android - TextView settext 显示单行而不是全部

android - lineSpacingExtra 和 lineSpacingMultiplier 有什么区别?

android - 如何判断我的 android 相机上的闪光灯硬件是否打开?

android - dp 中指定的边距在不同屏幕上的相对大小不同

python - 如何在解析 html 表时忽略 th 标签?