Skip to content Skip to sidebar Skip to footer

Control Fling Speed For Recycler View

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. The scroll is very smooth in android 4.4.4 and b

Solution 1:

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:

@Overridepublicbooleanfling(int velocityX, int velocityY)
{

     // if FLING_SPEED_FACTOR between [0, 1[ => slowdown 
     velocityY *= FLING_SPEED_FACTOR; 

     returnsuper.fling(velocityX, velocityY);
} 

Solution 2:

This works nicely to put a maximum threshold on the fling speed:

mRecyclerView.setOnFlingListener(newRecyclerView.OnFlingListener() {

    @OverridepublicbooleanonFling(int velocityX, int velocityY) {

        if (Math.abs(velocityY) > MAX_VELOCITY_Y) {
            velocityY = MAX_VELOCITY_Y * (int) Math.signum((double)velocityY);
            mRecyclerView.fling(velocityX, velocityY);
            returntrue;
        }

        returnfalse;
    }
});

Solution 3:

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

val maxFling=4000
        onFlingListener = object : RecyclerView.OnFlingListener() {
            overridefunonFling(velocityX: Int, velocityY: Int): Boolean {
                if (velocityY > maxFling) {
                    fling(velocityX, maxFling)
                    returntrue
                } elseif (velocityY < -maxFling) {
                    fling(velocityX, -maxFling)
                    returntrue
                } else {
                    returnfalse
                }

            }

        }

Solution 4:

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.SmoothScrollersmoothScroller=newFlexiSmoothScroller(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

Solution 5:

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

Post a Comment for "Control Fling Speed For Recycler View"