【问题标题】:How do I enable vertical AutoScroll in a TextView (Android)如何在 TextView (Android) 中启用垂直自动滚动
【发布时间】:2020-06-12 18:36:40
【问题描述】:

我的项目只包含一个 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.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】:
    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());
    

    【讨论】:

    • 我已经找了好几天了。非常感谢@ashakirov
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 2019-02-09
    • 2020-08-17
    • 1970-01-01
    相关资源
    最近更新 更多