Making TextView scrollable on Android

android multiline textview scrollable
android textview scroll horizontally
how to make edittext scrollable in android
android textview show scrollbar
scrollable textview android kotlin
kotlin textview scroll
scrollview android
scrolling activity android

I am displaying text in a textview that appears to be too long to fit into one screen. I need to make my TextView scrollable. How can I do that?

Here is the code:

final TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL);
tv.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent e) {
        Random r = new Random();
        int i = r.nextInt(101);
        if (e.getAction() == e.ACTION_DOWN) {
        return true;

You don't need to use a ScrollView actually.

Just set the

android:scrollbars = "vertical"

properties of your TextView in your layout's xml file.

Then use:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

in your code.

Bingo, it scrolls!

Making TextView scrollable on Android, To make TextView scrollable, you don't need to use ScrollView, just add android:​scrollbars=”vertical” attribute in TextView and then add two line  Android TextView allows user to display text in android application. In this tips, I will show how to make scrollable TextView in android. To make TextView scrollable, you don’t need to use ScrollView, just add android:scrollbars=”vertical” attribute in TextView and then add two line of code in your java activity file.

This is how I did it purely in XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""




  1. android:fillViewport="true" combined with android:layout_weight="1.0" will make the textview take up all available space.

  2. When defining the Scrollview, DO NOT specify android:layout_height="fill_parent" otherwise the scrollview doesn't work! (this has caused me to waste an hour just now! FFS).


To programmatically scroll to the bottom after appending text, use this:

mTextStatus = (TextView) findViewById(;
mScrollView = (ScrollView) findViewById(;

private void scrollToBottom()
{ Runnable()
        public void run()
            mScrollView.smoothScrollTo(0, mTextStatus.getBottom());

How to Make Scrollable TextView in Android, John's Android Studio Tutorials 139,800 views · 2:17 · Android how to make ScrollView auto Duration: 4:44 Posted: Nov 6, 2016 Making textview text is scrollable is very easy with the use of android:scrollbars=”vertical” attribute inside textview text widget this attribute will enable scrollbar display as vertically format and now we have to add setMovementMethod(new ScrollingMovementMethod()); on textview through programming file. This method will enable scrolling on TextView.

All that is really necessary is the setMovementMethod(). Here's an example using a LinearLayout.

File main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
public class WordExtractTest extends Activity {

    TextView tv1;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        tv1 = (TextView)findViewById(;


    private void loadDoc() {

        String s = "";

        for(int x=0; x<=100; x++) {
            s += "Line: " + String.valueOf(x) + "\n";

        tv1.setMovementMethod(new ScrollingMovementMethod());


Android Scrollable TextView, How to make TextView scrollable in Android applications Take your app to the top keyword Duration: 1:28 Posted: Oct 7, 2014 Android Scrollable TextView | Vertical Using XML and Programmatically Posted February 18, 2020 February 18, 2020 by Rohit Making TextView scrollable on Android you need to use a android:scrollbars properties of your TextView in your layout’s XML file.

Make your textview just adding this

TextView textview= (TextView) findViewById(;
textview.setMovementMethod(new ScrollingMovementMethod());

Android ScrollView (Horizontal, Vertical) with Examples, This example demonstrates how do I create a scrollable textView in android app.​Step 1 − Create a new project in Android Studio, go to File  Dynamically adjusting the size of text on Android with a simple API. TextView auto-sizing was introduced to the framework with Android 8.0 Oreo (API 26). It offers a simple yet powerful API to solve a particular problem: scaling of text size to fit text bounds.

It is not necessary to put in


You can do your work by simply adding:

android:scrollbars = "vertical"

And, put this code in your Java class:

textview.setMovementMethod(new ScrollingMovementMethod());

Android ScrollView Vertical, To make a TextView scrollable in android java, Add these lines in your project. In XML : android:maxLines="1000" android:scrollbars = "vertical". I am finding a tough time setting the textview with vertical scrolling text. In my dialog I have a textview with large text, since dialog is small window I want the textview text to scroll the vertically so that dialog looks good. Below is my xml

How to make TextView scrollable in Android applications, android:maxLines Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute value must be  How to make edittext in Android scrollable? Ask Question Asked 8 years, 11 months ago. Active 2 years, 2 months ago. Making TextView scrollable on Android.

How to create a scrollable textView Android app?, To make a View (such as a TextView ) scrollable, embed the View inside a ScrollView . Add a ScrollView between the article_subheading TextView and the article TextView . Choose wrap_content from the suggestions for both attributes. This example demonstrates how do I create a scrollable textView in android app. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/

How to Make a TextView Scrollable in Android Java, Today we're going to do a script that will make a scrolling Android TextView. I found this one useful when I'm testing my other code snippets. The situation is, my  The "pro tip" above from Someone Somewhere (Making TextView scrollable on Android) works great, however, what if you're dynamically adding text to the ScrollView and would like to automatically scroll to the bottom after an append only when the user is at the bottom of the ScrollView? (Perhaps because if the user has scrolled up to read

  • But surely maxLines requires you to enter an arbitrary number; this isn't something that will work for every screen size and font size? I find it simpler to just wrap it with a ScrollView, meaning I don't have to add any further XML attributes or code (like setting the movement method).
  • @Christopher, ScrollView requires 'android:layout_height' too.
  • @Regex: Well yes. Either you let the ScrollView take up as much space as it needs (e.g. via the android:fillViewport attribute), or you set the specific size you want. Using maxLines should not be used to set sizes of UI elements, so that is no solution.
  • you dont need to define maxlines. just the rest.
  • To clarify what everyone is saying about "smooth" scrolling: If you use this method scrolling is actually "smooth" (in that you can scroll pixel by pixel), however it is not kinetic. As soon as you remove your finger it stops scrolling instantly - there is no flicking. This is pretty unacceptable for a modern UI so I'm going to edit the answer to make sure other people don't waste time on this "solution".
  • There's no need to use mTextView.getBottom(), just use the method mScrollView.fullScroll(View.FOCUS_DOWN) as it is a part of the ScrollView API. See here and here for more info.
  • Android warns that either the LinearLayout or the ScrollView may be useless in this example (I removed the LinearLayout completely). It also warns that for the TextView, it should be android:layout_height="wrap_content" to match the ScrollView. These warnings may be due to the 3 years that have passed since this answer was posted. Regardless, this answer supports smooth scrolling and flicking...+1
  • Adding <!--suppress AndroidLintUselessParent --> above the ScrollView in the xml file will take care of those warnings.
  • The "pro tip" doesn't work for me, in Android API level 9. The textview stays scrolled to the top after appending text.
  • This approach is much better using the accepted answer approach will not produce a smooth user experience.
  • Is there any way to set this property in XML? I wonder why they would leave out that option.
  • It works but Is der any way to refresh it after scrolling? i mean after scrolling the TextView i am going to change text on it, but its position remains scrolled even if it is not required. its bcose previously i had applied scroll...
  • no scroll bars, and scrolling is clunky compared to the ScrollView method.
  • Use a StringBuilder instead of a String... what you have is a little wasteful.