0

I have a RecyclerView which I want to be scrolled only programmatically with smoothScrollToPosition command and not from user swipe events. I tried all the solutions from this post without success.

Any suggestions on how to solve this problem?

stavros.3p
  • 2,244
  • 6
  • 20
  • 37

1 Answers1

1

I didn't yet try it but I think overriding the onTouch will do the trick. You could do:

mRecyclerview.setOnTouchLisntener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

These methods will consume the touch event while doing nothing with it.

EDIT: Noticed you need to keep the click functionality:

mRecyclerview.setOnTouchLisntener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    return true;
                case MotionEvent.ACTION_UP:
                    return false;
                case MotionEvent.ACTION_MOVE:
                    return true;
            }
            return false;
        }
    });
Alex Newman
  • 1,369
  • 12
  • 34