Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 847
Sanchit Paurush Avatar asked Apr 13 '12 09:04

Sanchit Paurush


3 Answers

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>
like image 187
Arif Nadeem Avatar answered Oct 25 '22 00:10

Arif Nadeem


Check below code

   <TextView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#000000"
        android:textSize="17dip"
        android:inputType="textMultiLine"
        android:scrollbars="vertical"
    />
like image 29
Sandip Jadhav Avatar answered Oct 25 '22 00:10

Sandip Jadhav


It is possible to create multiline text view with scroll view. I used the following code in your application:

Txt_VistaRecetasola =  (TextView) findViewById(R.id.txt_vistarectsola);        
Txt_VistaRecetasola.setMovementMethod(ScrollingMovementMethod.getInstance());
Txt_VistaRecetasola.setScrollBarStyle(0x03000000);
Txt_VistaRecetasola.setVerticalScrollBarEnabled(true);
Txt_VistaRecetasola.setTextColor(0xFF000000);    
like image 38
Akash Singh Avatar answered Oct 25 '22 00:10

Akash Singh