Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

Android display long long text

I'm working on this case for several days. I have a file with 20 thousands lines text to be displayed in an activity.

I use a TextView in a ScrollView to display the text. Everything goes on well except that the TextView takes 3-5 seconds to draw the text. During this drawing time, if I want to scroll the view, I am getting ANR error

Is there any solution to avoid the ANR warning?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For that task I've developed a library (class) called LongTextView: https://github.com/metalurgus/LongTextView

Usage:

<com.metalurgus.longtextview.LongTextView 
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:gravity="left|top"
    app:maxLinesPerItem="2"
    app:text="@string/long_text"
    app:textColor="#ff0000"
    app:textSize="5dp" />

How it works:

It splits whole text into parts, and shows it as a ListView items using recycling, and therefore - with no UI lag and OOM due to enormous TextView


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...