Unable to autoscroll text in TextView

I am trying to create an automatic scroll of a TextView when my text is too long. I followed every tutorial or tips posted here on stackoverflow (yes, I read a bunch of topics similar to this, but no one fixed it).

So, I have my activity layout:

<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 this:

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

music_name is a TextView.

So even do everything that my TextView does not scroll. What could be wrong?

EDIT [NEW]: I noticed that it only works for the first time. In other cases, when I change text in a TextView, it no longer works. What could this do? I have a Timer that wakes up every 50 ms to update SeekBar and the other two TextViews, can this block something?

+3
4

TextView . , , :

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

gravity , TextView , . , , .

music_name.setMovementMethod(new ScrollingMovementMethod());.

, .

+2

, - scroll_textview_animation.xml res:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXDelta="200"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-200" />

onCreate :

music_name.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.scroll_textview_animation));

:

music_name.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            music_name.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.scroll_textview_animation));
        }
    });
0
<TextView
    android:id="@+id/mytext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="very long text to srollll abcdefghijklmnopqrstdaghlfj'ogjpsroshsrfjhrdjdjkdjdkjdk" 
    android:singleLine="true" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:ellipsize="marquee"
    android:focusable="true" 
    android:focusableInTouchMode="true"/>
0
source
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp">

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</ScrollView>

And define addTextChangedListener

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

        //some code here

    ScrollView scrollView1 = (ScrollView) findViewById(R.id.scrollView1);
    TextView textView1 = (TextView) findViewById(R.id.textView1);
    textView1.addTextChangedListener(new TextWatcher() {

    @Override
    public void afterTextChanged(Editable arg0) {
        scrollView1.fullScroll(ScrollView.FOCUS_DOWN);
        // you can add a toast or whatever you want here
    }

    @Override
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,     int arg3) {
        //override stub
    }

    @Override
    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int     arg3) {
        //override stub
    }

}) }
0
source

All Articles