如何在 TextView 中启用垂直自动滚动 (Android)

How do I enable vertical AutoScroll in a TextView (Android)

我的项目只包含一个文本视图,其内容是一个非常长的文本(大约 200 行文本)。用户可以在阅读文本时滚动文本,或者简单地启用自动滚动,他们可以通过 seekBar 控制自动滚动的速度。

我无法使用恒定速度完成 textView 中文本的恒定自动滚动。

下面是我的XML布局

 <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:fillViewport="true"
        android:layout_below="@id/autoScrollSwitch"
        android:scrollbars="vertical">
            <TextView
                android:id="@+id/dance_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"
                android:textSize="15sp" />

    </ScrollView>

我尝试过以多种不同的方式滚动 scrollView,例如;

    scrollView.smoothScrollTo(0, scrollView.getBottom()); // This is too fast and not constant

这个:

ObjectAnimator animator=ObjectAnimator.ofInt(scrollView, "scrollY",targetYScroll );
animator.setDuration(8000);
animator.start();   //This works by acceleration i.e start scrolling slowly before accelerating then starts decelerating towards the end.. I need constant scrolling

我应该如何最好地实现这一目标?

ObjectAnimator animator = ObjectAnimator.ofInt(scrollView, "scrollY", targetYScroll )
//This works by acceleration i.e start scrolling slowly before accelerating 
//then starts decelerating towards the end.. I need constant scrolling

恕我直言,这是一个很好的解决方案。使用 LinearInterpolator 线性滚动速度

animator.setInterpolator(new LinearInterpolator());