Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextView Scrollable

I have a textView which size is 16 characters, if it exceeds 16 characters I want to make it scrollable to the user to view remaining characters. Could any one help me?

I have tried this link Making TextView scrollable on Android

But there is no result?

My TextView Layout:

<TextView  
    android:id="@+id/tv1"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:maxLength="16"
       android:scrollbars = "vertical"
       android:ellipsize="end"
    android:text="fdgdddhhhdhd"
    />
like image 785
String Avatar asked Nov 28 '22 07:11

String


2 Answers

In your XML layout file:

<TextView
    android:id="@+id/message_scroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:text="@string/lorem" />

In your Java class file:

TextView tv = (TextView) rootView.findViewById(R.id.message_scroll);
tv.setMovementMethod(new ScrollingMovementMethod());
like image 61
Alaeddine Zidi Avatar answered Dec 04 '22 19:12

Alaeddine Zidi


Wrap your textview in a scrollview:

<ScrollView
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >
        <TextView  
            android:id="@+id/tv1"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:maxLength="16"
            android:scrollbars = "vertical"
            android:ellipsize="end"
            android:text="fdgdddhhhdhd" />
</ScrollView>
like image 31
Tarun Avatar answered Dec 04 '22 21:12

Tarun