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

问题描述 投票:0回答:1

我的项目只包含一个textView,其内容是一个很长的文本(大约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

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

android android-studio textview scrollview android-animation
1个回答
0
投票
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());
© www.soinside.com 2019 - 2024. All rights reserved.