以编程方式控制ScrollView Android的滚动速度

3

我在一个ScrollView中放置了一个TextView。我使用以下代码进行编程滚动。

mScrollView.post(new Runnable() { 
                    public void run() { 
                         mScrollView.scrollTo(0, mScrollView.getBottom());

                    } 
            });

它现在运行良好,但是我想以不同的速度控制scrollview的滚动速度。怎么做呢?

2个回答

3

或者您可以使用动画来实现平滑滚动

ObjectAnimator animator=ObjectAnimator.ofInt(yourScrollView, "scrollY",targetYScroll );
animator.start();

我之前在某个地方看到过这个答案,不管怎样,通过添加代码它对我起作用了: animator.setDuration(9000); 无论如何还是谢谢! - Dev Gurung

2
经过一番搜索,我找到了解决方法。以下是我用来在代码中编程减慢ScrollView滚动速度的代码:
 ObjectAnimator anim = ObjectAnimator.ofInt(mScrollView, "scrollY", mScrollView.getBottom());                               
 anim.setDuration(9000);                     
 anim.start();

mScrollView - 您的滚动视图

mScrollView = (ScrollView) findViewById(R.id.scrollView1);

anima.setDuration(int Value) - 这个值越大,滚动得越慢。我在Switch按钮的OnCheckedChangedListener中使用了这段代码块。


你应该更新你的答案并接受帮助了你的答案。 - Murtaza Khursheed Hussain

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接