Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...