control fling speed for recycler view

后端 未结 5 535
野的像风
野的像风 2021-02-07 18:02

I have a RecyclerView in which i have an image ,a few TextViews and 2 ImageButtons. I have 7-8 such rows to display in my Activity

相关标签:
5条回答
  • 2021-02-07 18:30

    I had the same problem. Here is the solution to slow down the fling.

            val maxFling=4000
            onFlingListener = object : RecyclerView.OnFlingListener() {
                override fun onFling(velocityX: Int, velocityY: Int): Boolean {
                    if (velocityY > maxFling) {
                        fling(velocityX, maxFling)
                        return true
                    } else if (velocityY < -maxFling) {
                        fling(velocityX, -maxFling)
                        return true
                    } else {
                        return false
                    }
    
                }
    
            }
    
    0 讨论(0)
  • 2021-02-07 18:31

    There is one RecyclerView method specifically designed to control the fling speed you only need to override it to achieve the friction/slowdown effect you mentioned in your question.

    One simple implementation you could try:

    @Override
    public boolean fling(int velocityX, int velocityY)
    {
    
         // if FLING_SPEED_FACTOR between [0, 1[ => slowdown 
         velocityY *= FLING_SPEED_FACTOR; 
    
         return super.fling(velocityX, velocityY);
    } 
    
    0 讨论(0)
  • 2021-02-07 18:38

    RecyclerView is great in that it is super modular. you can set your custom scroller to the LayoutMananger

    You can use https://github.com/apptik/MultiView/tree/master/scrollers

    Example:

    RecyclerView.SmoothScroller smoothScroller = new FlexiSmoothScroller(getContext())
                                .setMillisecondsPerInchSearchingTarget(100f));
    smoothScroller.setTargetPosition(targetPos);
    recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
    

    you can check more examples at: https://github.com/apptik/MultiView/blob/master/app/src/main/java/io/apptik/multiview/ScrollersFragment.java

    0 讨论(0)
  • 2021-02-07 18:39

    to control your recycler view's scroll speed See this SO post: Snappy scrolling in RecyclerView

    Basically you could override recyclerviews smoothScroll, or implement your own onGestureListener and attach it to the recyclerView

    0 讨论(0)
  • This works nicely to put a maximum threshold on the fling speed:

    mRecyclerView.setOnFlingListener(new RecyclerView.OnFlingListener() {
    
        @Override
        public boolean onFling(int velocityX, int velocityY) {
    
            if (Math.abs(velocityY) > MAX_VELOCITY_Y) {
                velocityY = MAX_VELOCITY_Y * (int) Math.signum((double)velocityY);
                mRecyclerView.fling(velocityX, velocityY);
                return true;
            }
    
            return false;
        }
    });
    
    0 讨论(0)
提交回复
热议问题