Scroll Speed/Duration For ScrollView/HorizontalScrollView

Nathan Sokalski 4,111 Reputation points
2022-06-08T16:50:35.047+00:00

I have a HorizontalScrollView for which I would like to control the duration when calling methods to scroll to different positions (such as SmoothScrollTo or ScrollTo, I don't care whether I use Smooth Scrolling or not). For my RecyclerView(s) I created a custom LinearSmoothScroller & did an override of CalculateSpeedPerPixel. I would prefer to not need to do this, so is there another way to specify the time/duration, or do I need to create a custom LinearSmoothScroller for my HorizontalScrollView as well?

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-06-09T08:24:17.46+00:00

    Hello,

    is there another way to specify the time/duration

    Yes, you could customize a ScrollView, and override the Fling method, if it is a HorizontalScrollView, the parameter is velocityX. Refer to the following code:

    public class MyScrollView : ScrollView  
    {  
        ......  
        public override void Fling(int velocityY)  
        {  
            base.Fling(velocityY / 5);// one-fifth the speed, you can set other values  
        }  
    }  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.