4

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" /> 
4
  • show your TextView layout Commented May 26, 2014 at 15:33
  • I added textview please check Commented May 26, 2014 at 15:40
  • You can use this : TextView.setMovementMethod(new ScrollingMovementMethod()); with TextView.setselected(true); ... Commented May 6, 2015 at 11:54
  • Possible duplicate of Making TextView Scrollable in Android Commented Feb 5, 2016 at 21:46

3 Answers 3

26

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()); 
Sign up to request clarification or add additional context in comments.

1 Comment

This is amazing but how can I scroll both vertically and horizontally?
5

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> 

Comments

1

Your android:maxlength="16" limits the number of characters that can be placed in the TextView to 16

According to the developer site

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.