How to display multiple lines of text with scrolli

2019-06-19 02:31发布

问题:

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.

回答1:

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>


回答2:

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);    


回答3:

Check below code

   <TextView 
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:textColor="#000000"
        android:textSize="17dip"
        android:inputType="textMultiLine"
        android:scrollbars="vertical"
    />


回答4:

Try using Edittext with making it un editable, so in this case it wont allow keyboard to popup.



回答5:

android:windowSoftInputMode="stateAlwaysHidden" in your Manifest file in the activity where you have your EditText.