control fling speed for recycler view

后端 未结 5 614
野的像风
野的像风 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:46

    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;
        }
    });
    

提交回复
热议问题