By Muhammad Maqsoodur Rehman


2009-11-17 13:43:03 8 Comments

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.setBackgroundResource(R.drawable.splash);
tv.setTypeface(face);
tv.setTextSize(18);
tv.setTextColor(R.color.BROWN);
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) {
            tv.setText(tips[i]);
            tv.setBackgroundResource(R.drawable.inner);
        }
        return true;
    }
});
setContentView(tv);

27 comments

@Raluca Lucaci 2019-05-29 08:01:18

In kotlin for making the textview scrollable

myTextView.movementMethod= ScrollingMovementMethod()

and also add in xml this property

    android:scrollbars = "vertical"

@mohamad sheikhi 2019-02-16 05:09:10

Try this:

android:scrollbars = "vertical"

@hash 2018-11-05 11:23:43

XML - You can use android:scrollHorizontally Attribute

Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally).

May be a boolean value, such as "true" or "false".

Prigramacaly - setHorizontallyScrolling(boolean)

@Amit Chintawar 2010-07-15 14:07:04

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!

@Christopher Orr 2010-12-19 22:57:18

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).

@Regex Rookie 2011-03-04 16:39:18

@Christopher, ScrollView requires 'android:layout_height' too.

@Christopher Orr 2011-03-05 12:18:48

@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.

@shadyyx 2011-05-14 15:24:02

Hello. For me this is not a solution (as I thought it is). I have to create all the layout programatically here and when using just a TextView with ScrollMovementMethod(), it scrolls like a 3 px/scroll and very jerky. This TextView is in LineraLayout which is within a ScrollView. When I try to surround thhis TextView with another ScrollView - how can I set the height for it??? Remember - I'm not using any XML here...and ScrollView does not have a .setHeight() method. Any suggestion?

@Stevanicus 2011-06-08 13:38:57

you dont need to define maxlines. just the rest.

@ubuntudroid 2011-09-21 13:50:46

You don't even have to do the TextView.setMovementMethod(..) stuff ;), setting android:scrollbars is actually enough.

@Sunny 2012-04-09 17:07:07

@ubuntudroid it is necessary to add this method. If your text is larger then the textview if will not scroll.

@ubuntudroid 2012-04-10 09:21:47

@Sunny Well in my experience it does without any problems. Tried on stock Android 2.3.6. May depend on the Android version though.

@Zeeshan Chaudhry 2012-08-27 05:40:33

This solution didn't Scroll scrolls automatically for me. i get the scroll with tap/click but that didnt scroll automatically. how to make it scroll automatically just like vertical mrquee.

@caw 2012-12-01 20:30:01

@Christopher: Setting android:maxLines isn't necessary.

@smkrn110 2013-04-18 08:31:39

thanks thats really worked, and I have used it without mentioning "maxLines", but in my case I has to put yourTextView.setMovementMethod(new ScrollingMovementMethod()), without it, in my case not worked.

@Matt Logan 2013-10-21 02:00:04

It seems like to you have to surround the TextView with a ScrollView for it to scroll smoothly.

@KarenAnne 2013-10-23 03:19:35

I found out that LinkMovementMethod already "traverses links in the text buffer and scrolls if necessary." Thanks for the idea about maxLines and scrollBars. I spent hours figuring about this, and this saved me from wasting more time!

@Peter Carpenter 2013-10-29 04:42:08

I found a way to do this without XML. I've posted it here: stackoverflow.com/questions/19649334/…

@Behnam 2014-01-14 08:34:12

I don't know what you all are talking about, I have to actually scroll manually to see the text. My idea of auto-scrolling is a TextView that scrolls back and forth without user intervention. Anybody any Idea please?

@Ollie Strevel 2014-01-20 17:20:41

This is actually the best and the easiest answer for this :) This is the equivalent programmatically: text.setMaxLines(4); text.setVerticalScrollBarEnabled(t‌​rue); text.setHorizontalScrollBarEnabled(true); text.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY)‌​; text.setMovementMethod(new ScrollingMovementMethod());

@Deb 2015-01-08 19:34:25

Where is "Smoothness" of scroll?

@Murtaza Khursheed Hussain 2015-01-22 07:08:14

doesn't need to set max-lines

@Nishit Shah 2015-06-21 13:57:29

scrolling is not smooth. how to achieve that?

@Simas 2015-08-17 17:48:53

@NishitShah use a ScrollView.

@Timmmm 2015-11-09 15:39:57

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".

@Amit Chintawar 2015-11-10 08:52:01

@Timmmm the answer has been accepted 804 times already. So the behavior is acceptable to most devs. And nowhere in the question and answer there is mention of kinetic scrolling. You should not edit an answer just because it does not fulfil your requirements. I think a comment that you made is good enough.

@Timmmm 2015-11-10 14:25:32

Kinetic scrolling is an implicit requirement. And I edited the question because you have to scroll down through many ambiguously-worded comments to find out that it doesn't support kinetic scrolling. Shadyyx, Matt Logan, Pratik Butani, Deb, Nishit Shah and Simas have all noted that this doesn't work without issues - I'm sure they would have appreciated my edit. Someone Somewhere's answer is the best (and it has many upvotes) but for some reason is way way down the page).

@Usman Rana 2016-05-30 10:30:20

Scroller of TextView is not that much fast as it is in ScrollView. I tried this solution and then shifted to the solution of @Someone Somewhere.

@Mateusz Konieczny 2018-03-11 16:04:20

According to stackoverflow.com/questions/1748977/… maxlines is not needed.

@John 2018-05-29 21:22:45

Once I put my TextView in a FrameView I couldn't work out why it stopped working, it looks a dirty hack but TextView.setMovementMethod(..) is totally necessary.

@Prince 2018-07-12 12:49:51

whenever you need to use the ScrollView as parent, And you also use the scroll movement method with TextView. And When you portrait to landscape your device that time occur some issue. (like) entire page is scrollable but scroll movement method can't work. if you still need to use ScrollView as parent or scroll movement method then click on link stackoverflow.com/questions/1748977/…

@Prince 2018-07-12 12:48:41

whenever you need to use the ScrollView as parent, And you also use the scroll movement method with TextView.

And When you portrait to landscape your device that time occur some issue. (like) entire page is scrollable but scroll movement method can't work.

if you still need to use ScrollView as parent or scroll movement method then you also use below desc.

If you do not have any problems then you use EditText instead of TextView

see below :

<EditText
     android:id="@+id/description_text_question"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="@null"
     android:editable="false"
     android:cursorVisible="false"
     android:maxLines="6"/>

Here, the EditText behaves like TextView

And your issue will be resolved

@Rohit Mandiwal 2018-06-06 01:23:18

I had this problem when I was using TextView inside the ScrollView. This solution has worked for me.

scrollView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                description.getParent().requestDisallowInterceptTouchEvent(false);

                return false;
            }
        });

        description.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                description.getParent().requestDisallowInterceptTouchEvent(true);

                return false;
            }
        });

@Khemraj 2018-05-13 18:25:21

Put maxLines and scrollbars inside TextView in xml.

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:maxLines="5" // any number of max line here.
    />

Then in java code.

textView.setMovementMethod(new ScrollingMovementMethod());

@Kamil Ibadov 2017-03-06 05:09:39

Use it like this

<TextView  
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:maxLines = "AN_INTEGER"
    android:scrollbars = "vertical"
/>

@MBH 2016-02-05 08:23:42

Simple. This is how I did it:

  1. XML Side:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        tools:context="com.mbh.usbcom.MainActivity">
        <TextView
            android:id="@+id/tv_log"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:text="Log:" />
    </RelativeLayout>
    
  2. Java side:

    tv_log = (TextView) findViewById(R.id.tv_log);
    tv_log.setMovementMethod(new ScrollingMovementMethod());
    

Bonus:

To let the text view scroll down as the text fill it, you have to add:

    android:gravity="bottom"

to the TextView xml file. It will scroll down automatically as more text comes in.

Of course you need to add the text using the append function instead of set text:

    tv_log.append("\n" + text);

I used it for Log purpose.

I hope this helps ;)

@Ahsan Raza 2016-06-05 04:38:38

It is not necessary to put in

android:Maxlines="AN_INTEGER"`

You can do your work by simply adding:

android:scrollbars = "vertical"

And, put this code in your Java class:

textview.setMovementMethod(new ScrollingMovementMethod());

@FractalBob 2017-04-05 01:02:35

Much better solution than the accepted one, as the scrollbar size exactly fits the text and you don't waste space.

@Prince 2018-07-12 12:20:37

when i am using ScrollView as parent, that time its not working

@Petro 2014-12-21 18:32:34

I struggled with this for over a week and finally figured out how to make this work!

My issue was that everything would scroll as a 'block'. The text itself was scrolling, but as a chunk rather than line by line. This obviously didn't work for me, because it would cut off lines at the bottom. All of the previous solutions did not work for me, so I crafted my own.

Here is the easiest solution by far:

Make a class file called: 'PerfectScrollableTextView' inside a package, then copy and paste this code in:

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class PerfectScrollableTextView extends TextView {

    public PerfectScrollableTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setVerticalScrollBarEnabled(true);
        setHorizontallyScrolling(false);
    }

    public PerfectScrollableTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setVerticalScrollBarEnabled(true);
        setHorizontallyScrolling(false);
    }

    public PerfectScrollableTextView(Context context) {
        super(context);
        setVerticalScrollBarEnabled(true);
        setHorizontallyScrolling(false);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if(focused)
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean focused) {
        if(focused)
            super.onWindowFocusChanged(focused);
    }

    @Override
    public boolean isFocused() {
        return true;
    }
}

Finally change your 'TextView' in XML:

From: <TextView

To: <com.your_app_goes_here.PerfectScrollableTextView

@user3921740 2014-09-05 17:21:35

Add the following in the textview in XML.

android:scrollbars="vertical"

And finally, add

textView.setMovementMethod(new ScrollingMovementMethod());

in the Java file.

@Timmmm 2015-11-10 14:27:51

This does not do kinetic scrolling. Do not use it.

@Ritesh 2014-01-06 09:24:17

Add this to your XML layout:

android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="To Make An textView Scrollable Inside The TextView Using Marquee"

And in code you have to write the following lines:

textview.setSelected(true);
textView.setMovementMethod(new ScrollingMovementMethod());

@Timmmm 2015-11-10 14:28:07

This does not do kinetic scrolling. Do not use it.

@Sagar Nayak 2016-08-10 04:33:22

i dont want to ellipsize the end text. how do i do it.

@Francis 2018-11-05 11:49:56

@SagarNayak use android:ellipsize="none"

@Dipendra 2012-12-27 10:06:07

If you want text to be scrolled within the textview, then you can follow the following:

First you should have to subclass textview.

And then use that.

Following is an example of a subclassed textview.

public class AutoScrollableTextView extends TextView {

    public AutoScrollableTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setEllipsize(TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine();
        setHorizontallyScrolling(true);
    }

    public AutoScrollableTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setEllipsize(TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine();
        setHorizontallyScrolling(true);
    }

    public AutoScrollableTextView(Context context) {
        super(context);
        setEllipsize(TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine();
        setHorizontallyScrolling(true);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if(focused)
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean focused) {
        if(focused)
            super.onWindowFocusChanged(focused);
    }

    @Override
    public boolean isFocused() {
        return true;
    }
}

Now, you have to use that in the XML in this way:

 <com.yourpackagename.AutoScrollableTextView
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="This is very very long text to be scrolled"
 />

That's it.

@Rahul Baradia 2012-07-04 13:35:56

When you are done with scrollable, add this line to the view's last line when you enter anything in the view:

((ScrollView) findViewById(R.id.TableScroller)).fullScroll(View.FOCUS_DOWN);

@Rahul Baradia 2012-07-09 04:15:49

dude,tablescroller is a view that was identified by the id attribute from the XML that was processed in .. u just try it.. it ll work fine.. its works fr me..

@mOmO 2012-06-06 07:49:03

This is "How to apply ScrollBar to your TextView", using only XML.

First, you need to take a Textview control in the main.xml file and write some text into it ... like this:

<TextView
    android:id="@+id/TEXT"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/long_text"/>

Next, place the text view control in between the scrollview to display the scroll bar for this text:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent">

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_height="150px"
        android:layout_width="fill_parent">

        <TextView
            android:id="@+id/TEXT"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/long_text"/>

    </ScrollView>
</RelativeLayout>

That's it...

@Justin Buser 2012-07-08 14:44:00

Why even write this? This is an almost identical, albeit less correct, version of an answer that was posted over 6 months before you wrote it.

@Valentin Galea 2012-02-20 15:35:40

The best way I found:

Replace the TextView with an EditText with these extra attributes:

android:background="@null"
android:editable="false"
android:cursorVisible="false"

There is no need for wrapping in a ScrollView.

@Jason Polites 2012-05-10 00:10:37

android:editable and android:cursorVisible are deprecated

@Justin Buser 2012-07-08 15:38:47

Easily the best and most appropriate answer, especially considering that EditText is a TextView subclass and the question is how to make the textview scrollable, not how to work around the problem. Would vote up twice if I could :)

@Madbreaks 2012-10-24 00:53:52

@JustinBuser Couldn't disagree more. :) It's purely serendipitous that this works, and there's no guarantee it will in future versions of Android. If you want scrolling, use the scrolling tools that Android provides. ScrollView is the correct way to go.

@Justin Buser 2012-10-27 14:32:25

@Madbreaks There is nothing "serendipitous" about it, EditText IS a TextView with a few added methods and overrides that is specifically tailored to accommodate varying length text. In particular EditText overrides the return value for the TextView getDefaultMovementMethod function. The default implementation returns NULL, EditText basically does the same thing all these other answers are suggesting. As far as using the tools that Android provides is concerned, the EditText class is far less likely to become deprecated than any of the other methods found in these answers.

@Madbreaks 2012-10-29 17:57:56

@JustinBuser My problem with that though is you're depending on the default behavior of EditText, that is what I meant may very well change down the road (not at all that EditText would be deprecated). You can argue that, but again, the idea is to use components and features that are appropriate for the task at hand. ScrollView was explicitly designed to encompass scrolling. I always try to, and always suggest others use the right tool for the job. There are almost always multiple approaches to any given programming problem. Anyway, thanks for the thoughtful response.

@Someone Somewhere 2011-12-16 09:16:00

This is how I did it purely in XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ScrollView
        android:id="@+id/SCROLLER_ID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:fillViewport="true">

        <TextView
            android:id="@+id/TEXT_STATUS_ID"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"/>
    </ScrollView>
</LinearLayout>

NOTES:

  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).

PRO TIP:

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

mTextStatus = (TextView) findViewById(R.id.TEXT_STATUS_ID);
mScrollView = (ScrollView) findViewById(R.id.SCROLLER_ID);

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

@ChuongPham 2013-09-11 19:59:55

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.

@OneWorld 2014-03-03 12:19:44

Much better scrolling performance than the accepted answer.

@skia.heliou 2014-12-30 23:43:21

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

@Louie Bertoncin 2015-08-12 20:10:27

Adding <!--suppress AndroidLintUselessParent --> above the ScrollView in the xml file will take care of those warnings.

@LarsH 2016-04-21 19:14:58

The "pro tip" doesn't work for me, in Android API level 9. The textview stays scrolled to the top after appending text.

@seyedrezafar 2019-10-12 07:13:07

This approach is much better using the accepted answer approach will not produce a smooth user experience.

@EddieB 2011-04-12 17:23:15

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="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    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:text="@string/hello"
    />
</LinearLayout>

File WordExtractTest.java

public class WordExtractTest extends Activity {

    TextView tv1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv1 = (TextView)findViewById(R.id.tv1);

        loadDoc();
    }

    private void loadDoc() {

        String s = "";

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

        tv1.setMovementMethod(new ScrollingMovementMethod());

        tv1.setText(s);
    }
}

@Thalur 2011-11-22 16:16:35

Is there any way to set this property in XML? I wonder why they would leave out that option.

@Nirav Dangi 2011-11-23 10:03:40

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...

@Jeffrey Blattman 2012-09-14 21:59:54

no scroll bars, and scrolling is clunky compared to the ScrollView method.

@Alex Lockwood 2012-10-07 05:36:06

Use a StringBuilder instead of a String... what you have is a little wasteful.

@David Wasser 2013-04-09 13:01:07

@JeffreyBlattman actually, you can get scrollbars by adding android:scrollbars="vertical" to the TextView XML.

@Mejonzhan 2013-09-05 07:32:32

It really works, but when it is in listview item, does not work!

@frostymarvelous 2014-07-15 14:36:28

this works but the scrolling is not smooth. Still works though thanks.

@Samuh 2010-01-19 10:04:51

You can either

  1. surround the TextView by a ScrollView; or
  2. set the Movement method to ScrollingMovementMethod.getInstance();.

@Sasha 888 2017-03-23 09:46:44

In my case.Constraint Layout.AS 2.3.

Code implementation:

YOUR_TEXTVIEW.setMovementMethod(new ScrollingMovementMethod());

XML:

android:scrollbars="vertical"
android:scrollIndicators="right|end"

@whitepearl 2016-09-24 16:54:46

The code below creates an automatic horizontal scrolling textview:

While adding TextView to xml use

<TextView android:maxLines="1" 
          android:ellipsize="marquee"
          android:scrollHorizontally="true"/>

Set the following properties of TextView in onCreate()

tv.setSelected(true);
tv.setHorizontallyScrolling(true); 

@Mark Cramer 2013-05-20 16:46:26

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 something you don't want to automatically reset to the bottom during an append, which would be annoying.)

Anyway, here it is:

if ((mTextStatus.getMeasuredHeight() - mScrollView.getScrollY()) <=
        (mScrollView.getHeight() + mTextStatus.getLineHeight())) {
    scrollToBottom();
}

The mTextStatus.getLineHeight() will make it so that you don't scrollToBottom() if the user is within one line from the end of the ScrollView.

@matasoy 2013-07-26 01:59:59

Make your textview just adding this

TextView textview= (TextView) findViewById(R.id.your_textview_id);
textview.setMovementMethod(new ScrollingMovementMethod());

@Timmmm 2015-11-10 14:26:03

This does not do kinetic scrolling. Do not use this.

@Ciro Santilli 新疆改造中心法轮功六四事件 2016-02-05 21:29:23

@Timmmm how to get the kinetic scroll?

@Ciro Santilli 新疆改造中心法轮功六四事件 2016-02-05 21:39:21

@The incredible Jan 2018-03-20 09:57:42

You don't want "kinetic scrolling" for a text that has to be read.

@IT-Dan 2012-12-20 12:29:03

This will provide smooth scrolling text with a scroll bar.

ScrollView scroller = new ScrollView(this);
TextView tv = new TextView(this);
tv.setText(R.string.my_text);
scroller.addView(tv);

@Griffin W. 2013-04-22 04:28:50

Enables blue animation. Best answer here IMO.

@Justin Buser 2012-10-27 14:38:29

If you don't want to use the EditText solution then you might have better luck with:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yourLayout);
    (TextView)findViewById(R.id.yourTextViewId).setMovementMethod(ArrowKeyMovementMethod.getInstance());
}

@android.weasel 2011-05-15 15:59:36

I didn't find TextView scrolling to support the 'fling' gesture, where it continues scrolling after a flick up or down. I ended up implementing that myself because I didn't want to use a ScrollView for various reasons, and there didn't seem to be a MovementMethod that both allowed me to select text and click on links.

@Lou Morda 2014-11-20 22:59:28

soo... how did you add the fling gesture?

Related Questions

Sponsored Content

25 Answered Questions

[SOLVED] Is there a way to run Python on Android?

32 Answered Questions

[SOLVED] How to change fontFamily of TextView in Android

24 Answered Questions

[SOLVED] How to set TextView textStyle such as bold, italic

97 Answered Questions

30 Answered Questions

47 Answered Questions

[SOLVED] Is there a unique Android device ID?

33 Answered Questions

[SOLVED] How do I make links in a TextView clickable?

64 Answered Questions

[SOLVED] How do I center text horizontally and vertically in a TextView?

  • 2009-01-11 00:27:55
  • pupeno
  • 1181410 View
  • 1929 Score
  • 64 Answer
  • Tags:   android textview

77 Answered Questions

11 Answered Questions

[SOLVED] Proper use cases for Android UserManager.isUserAGoat()?

Sponsored Content