Displaying Formatted text

I have a data file with large blocks of text that have the paragraphs delimited by /r/r . Is there a way to display them in a TextView so that there is spacing between the paragraphs? (If necessary, I can regenerate the text with different delimiters.) There can be any number of paragraphs in a given page of text.
I have seen mentions of SpannableStringBuilder but I have been unable to find documentation/examples showing how to use it. Would this be the best solution?

Thanks,
Dan

Best Answer

  • DanDickersonDanDickerson US ✭✭
    Accepted Answer

    My primary desire was to include paragraph breaks in the text. I found how to do this in other threads. Adding maxLines to the axml solved the problem:

                <TextView
                    android:maxLines="50"
                    android:text="Line1\n\nLine2\nLine3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
    

    This results in:

        Line1
    
        Line2
        Line3
    

    Which is what I was looking for.

Answers

  • DanDickersonDanDickerson USMember ✭✭
    Accepted Answer

    My primary desire was to include paragraph breaks in the text. I found how to do this in other threads. Adding maxLines to the axml solved the problem:

                <TextView
                    android:maxLines="50"
                    android:text="Line1\n\nLine2\nLine3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
    

    This results in:

        Line1
    
        Line2
        Line3
    

    Which is what I was looking for.

Sign In or Register to comment.