Speed ​​Limit for Scrolling

My scroll app is super fast! How can I limit the scroll speed of a scroll in an Android app? Scrolling can be very fast, and it makes no sense to scroll this speed.

+3
source share
4 answers

This thread is old, but I will answer with a partial solution: speed limit. Feel free to comment, so I can improve my decision.

As explained in the Developer's Guide:

Flinging is a type of scrolling that occurs when the user drags and quickly raises his finger.

Where I needed the speed limit. Thus, in a custom ScrollView (horizontal or vertical), override the fling method as follows.

@Override public void fling(int velocityY) { int topVelocityY = (int) ((Math.min(Math.abs(velocityY), MAX_SCROLL_SPEED) ) * Math.signum(velocityY)); super.fling(topVelocityY); } 

I found that speedY (in horizontal scrolling, it will be velocityX) can be between -16000 and 16000. Negative simply means scrolling backward. I am still testing these values ​​and I tested them on only one device. Not sure if it's similar to older API devices / versions. I will come back later to edit this.

 (int) ((Math.min(Math.abs(velocityY), MAX_SCROLL_SPEED) ) * Math.signum(velocityY)); 

What I'm doing is getting the minimum value between my constant MAX_SCROLL_SPEED and the original speed Y, and then getting the sign of the original speed Y. We need a sign to scroll back.

Finally, sending back the changed speed.

This is a partial solution, because if the user continues to press scrollview, the speed will not change.

Again, feel free to improve your answer, I'm still learning.

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

I think using a timer, you can limit the scroll speed. look at this Android link : HorizontalScrollView smoothScroll animation time

0
source

This is how I got smooth vertical scrolling (like movies). It also allows the user to move the scroll up and down and let it continue to scroll when they release. In my XML, I encapsulated my TextView inside a ScrollView called "scrollView1". Enjoy it!

  final TextView tv=(TextView)findViewById(R.id.lyrics); final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1); Button start = (Button) findViewById(R.id.button_start); Button stop = (Button) findViewById(R.id.button_stop); final Handler timerHandler = new Handler(); final Runnable timerRunnable = new Runnable() { @Override public void run() { scrollView.smoothScrollBy(0,5); // 5 is how many pixels you want it to scroll vertically by timerHandler.postDelayed(this, 10); // 10 is how many milliseconds you want this thread to run } }; start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { timerHandler.postDelayed(timerRunnable, 0); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { timerHandler.removeCallbacks(timerRunnable); } }); 
0
source

Source: https://habr.com/ru/post/988150/


All Articles