Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot auto scroll text in TextView

I'm trying to have a auto scroll TextView when my text is too long. I followed every tutorial or tips posted here on stackoverflow (yes I readed a bunch of topics similar to this but no one fixed it).

So I have my activity layout like that:

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

....

<TextView
    android:id="@+id/music_name"
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:gravity="center"
    android:text="Music Name"
    android:textSize="24sp"
    android:layout_centerHorizontal="true"
    android:singleLine="true"
    android:scrollHorizontally="true"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:marqueeRepeatLimit="marquee_forever" />

....

</RelativeLayout>

And in OnCreate( ) I do that:

music_name.setSelected(true);
music_name.setMovementMethod(new ScrollingMovementMethod());

music_name is the TextView.

So even doing all that my TextView doesn't scroll. What could be wrong?

EDIT[NEW]: I noticed that it works only for the first time. The other times I change the text on the TextView it doesnt works anymore. What it could be doing that? I have thread (Timer) that wakes up every 50ms to update an SeekBar and other two TextViews, this could be blocking something?

like image 880
ferrazrafael Avatar asked May 09 '26 15:05

ferrazrafael


1 Answers

TextView sometimes comes tricky when handling scrolling. The main attributes you've to set into your layout are the following:

android:scrollHorizontally="false"
android:scrollbars="vertical"
android:gravity="bottom"

The gravity set to bottom will make your scrollbar descend to the bottom of your TextView everytime you append a line. So use that only if you want it to be that way.

The music_name.setMovementMethod(new ScrollingMovementMethod()); statement is also needed.

This way it should work.

like image 120
nKn Avatar answered May 11 '26 05:05

nKn