Dev Gurung
Dev Gurung

Reputation: 1288

Programmatically Control The Scrolling Speed of ScrollView Android

I have a TextView inside a ScrollView. I have used the below code to scroll programmatically.

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

                    } 
            });

It does fine. Now But I want to control the scrolling speed of scrollview in differend speed values. How to get it?

Upvotes: 3

Views: 5363

Answers (2)

Dev Gurung
Dev Gurung

Reputation: 1288

After few searches, this is what worked for me. Here is the code I used to slow down the scroll speed of ScrollView programmatically,

 ObjectAnimator anim = ObjectAnimator.ofInt(mScrollView, "scrollY", mScrollView.getBottom());                               
 anim.setDuration(9000);                     
 anim.start();

mScrollView - Your ScrollView

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

anima.setDuration(int Value) - greater the value, slower the scroll I used the code block in Switch Button OnCheckedChangedListener.

Upvotes: 2

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

Or you can animation for smooth scrolling

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

Upvotes: 3

Related Questions