0

I have a recyclerview which scrolls horizontally. I have disabled scrolling the recyclerview when user click on an item. Now if the user try to scroll the list when its lock I want to show a bounce effect that he/she cannot scroll further.

For example:

I have a list of 10 items and user clicked on the 5th item. Now the scroll is locked and when the user try to scroll I want to show a bounce effect that the user can't scroll.

Here is my custom LinearLayoutManager:

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.util.AttributeSet


class CustomLinearLayoutManager : LinearLayoutManager {
  private var isScrollEnabled = true

  constructor(context: Context) : super(context)

  constructor(context: Context, orientation: Int, reverseLayout: Boolean) : super(context, orientation, reverseLayout)

  constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)


  fun setScrollEnabled(flag: Boolean) {
    this.isScrollEnabled = flag
  }

  override fun canScrollHorizontally(): Boolean {
    //Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
    return isScrollEnabled && super.canScrollHorizontally()
  }
}

Here is my recyclerview enable/disable scroll code:

val layoutManager = CustomLinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
binding.recyclerView.layoutManager = layoutManager
layoutManager.setScrollEnabled(false)
sagar suri
  • 4,351
  • 12
  • 59
  • 122

1 Answers1

0

you can use bouncy recyclerview to achieve this functionality and use below link to user it BoucncyRecyclerview or else you can use Overscroll effect of recyclerview using OverScroll effect of recyclerview

niceumang
  • 1,347
  • 1
  • 8
  • 21
  • But the user can be at the middle of the list also. This will work when the user reaches the end or start of the recyclerview list. – sagar suri May 23 '19 at 06:03