Skip to content

Instantly share code, notes, and snippets.

@WSAyan
Created August 16, 2020 05:54
Show Gist options
  • Save WSAyan/720c3b3817f58aea36ced243d38e7089 to your computer and use it in GitHub Desktop.
Save WSAyan/720c3b3817f58aea36ced243d38e7089 to your computer and use it in GitHub Desktop.
Disable/enable default scrolling behavior of RecyclerView
import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
class CustomScrollableLinearLayoutManager(context: Context) : LinearLayoutManager(context) {
private var isVerticalScrollEnabled = true
private var isHorizontalScrollEnabled = true
fun setVerticalScrollEnabled(isVerticalScrollEnabled: Boolean) {
this.isVerticalScrollEnabled = isVerticalScrollEnabled
}
fun setHorizontalScrollEnabled(isHorizontalScrollEnabled: Boolean) {
this.isHorizontalScrollEnabled = isHorizontalScrollEnabled
}
override fun canScrollVertically(): Boolean {
return isVerticalScrollEnabled && super.canScrollVertically()
}
override fun canScrollHorizontally(): Boolean {
return isHorizontalScrollEnabled && super.canScrollHorizontally()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment