簡體   English   中英

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

[英]Android: Speeding up display of (html-formatted) text

我的應用程序使用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()));

這可以正常工作,但隨着文本數量的增長它變得非常慢。 例如,為了執行這三行代碼,顯示總共約50KB文本的50個段落花費超過5秒。

誰能建議我如何加快速度呢?拜托?

誰能建議我如何加快速度呢?拜托?

使用WebView而不是ScrollViewTextView

另外,正如Nick指出的那樣,通過使用Traceview或其他東西確認您花費的時間確實花費在您認為的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM