-1

I had a requirement where I need to create a scrollable textview in android.
for Example I had a a long Text that needs to displayed in TextView.
Initially it should show part of Text with a Hyperlink "showmore" . Click on "showmore" link should display full Text that scrolls the entire layout.


Can anyone help me to create this type of label ("TextView") in Android


Thanks in Advance

2 Answers2

1

n your XML layout file:

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

In your Java class file:

TextView mTextView = (TextView) findViewById(R.id.text_view);
mTextView.setMovementMethod(new ScrollingMovementMethod());
Noman Rafique
  • 3,392
  • 23
  • 29
0

If you want, you can add a ScrollView wrapping your TextView:

<ScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scrollbars="vertical"
  android:padding="10dp"
  android:layout_margin="5dp">
    <TextView
      android:id="@+id/textView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:textSize="18sp"/>
  </ScrollView>
MetaSnarf
  • 5,371
  • 2
  • 20
  • 37