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)