Search code examples
androidscrolltextviewandroid-edittext

How to display multiple lines of text with scrolling in android?


I want to display multiple lines of text in my application in particular range such that user can scroll to view other lines. I have tried EditText, but it generates keyboard on top of it and doesn't scroll properly. Then I tried TextView, it also does not scroll the text properly as I wanted.

Is there any other option available? If No, then how to scroll the text vertically in TextView or EditText? I want to scroll the text on drag as in WebView. NOT auto scroll.


Solution

  • You can limit the Height of TextView to match the number of lines you user wants to see, then simply put your TextView in a ScrollView

    I had done a simple example to demonstrate this...

    <ScrollView android:layout_height="30dp"
            android:layout_width="match_parent">
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:textSize="16sp"
        android:id="@+id/tv1"
        />
    </ScrollView>