Translate

Android: Making a TextView Scrollable

I needed a TextView to take the rest of the screen realstate. This TextView would behave as a logging component.
I tried using android:singleLine=”false” but that didn’t cut it.

What I did:
Add a ScrollView (with android:fillViewport=”true” and android:layout_weight=”1″), then add a LinearLayout (yup…), and then add the TextView to fill all of that up (android:layout_weight=”1″ too)

Here’s the only thing that worked for me:

	<ScrollView android:layout_width="fill_parent"
                              android:layout_height="wrap_content"
                              android:layout_weight="1" android:fillViewport="true">
		<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
		<TextView android:text="@+id/TextView01"
			android:id="@+id/logTextView"
			android:layout_width="fill_parent"
			android:layout_height="fill_parent"
			android:textColor="#000"
			android:background="#fff"
			android:layout_weight="1"></TextView>
		</LinearLayout>
	</ScrollView>

Then on your Activity, do this:

_logTextView = (TextView) findViewById(R.id.logTextView);
_logTextView.setText("");

//and here comes the magic
_logTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

3 Responses to “Android: Making a TextView Scrollable”

  1. Nandroid Says:

    Gud and easy!!!
    Bt scroll is small and not workin for whole text!!!

  2. Melissa Says:

    This might help: http://blog.teamgrowth.net/index.php/android/how-to-make-the-textview-in-android-scrollable

  3. Arend Says:

    Works great, many thanks.

Leave a Reply