Reduce speed of smooth scroll in scroll view

后端 未结 5 1047
栀梦
栀梦 2021-02-03 19:44

I have a scroll View. I performed smooth-scroll.using smoothScrollBy().It all works fine, but I want to change the duration of the smooth-scroll. Smooth-scroll happens very fast

5条回答
  •  佛祖请我去吃肉
    2021-02-03 20:19

    Try the following code:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
        ValueAnimator realSmoothScrollAnimation = 
            ValueAnimator.ofInt(parentScrollView.getScrollY(), targetScrollY);
        realSmoothScrollAnimation.setDuration(500);
        realSmoothScrollAnimation.addUpdateListener(new AnimatorUpdateListener()
        {
            @Override
            public void onAnimationUpdate(ValueAnimator animation)
            {
                int scrollTo = (Integer) animation.getAnimatedValue();
                parentScrollView.scrollTo(0, scrollTo);
            }
        });
    
        realSmoothScrollAnimation.start();
    }
    else
    {
        parentScrollView.smoothScrollTo(0, targetScrollY);
    }
    

提交回复
热议问题