Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Control The Scrolling Speed of ScrollView Android

Tags:

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?

like image 943
Dev Gurung Avatar asked Dec 05 '25 09:12

Dev Gurung


2 Answers

Or you can animation for smooth scrolling

ObjectAnimator animator=ObjectAnimator.ofInt(yourScrollView, "scrollY",targetYScroll );
animator.start();
like image 106
Murtaza Khursheed Hussain Avatar answered Dec 12 '25 13:12

Murtaza Khursheed Hussain


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.

like image 32
Dev Gurung Avatar answered Dec 12 '25 14:12

Dev Gurung