Skip to content

Instantly share code, notes, and snippets.

@momvart
Last active May 3, 2020 10:46
Show Gist options
  • Save momvart/281f0e84f31c8288fb224c7d003b9985 to your computer and use it in GitHub Desktop.
Save momvart/281f0e84f31c8288fb224c7d003b9985 to your computer and use it in GitHub Desktop.
A simple extension of GridLayoutManager which makes it possible to lock/disable/set the read-only scroll properties for your recyclerview
import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
class ScrollLockableGridLayoutManager(context: Context, spansCount: Int) : GridLayoutManager(context, spansCount) {
var canScrollVertically = true
override fun canScrollVertically(): Boolean =
if (!canScrollVertically) false
else super.canScrollVertically()
var canScrollHorizontally = true
override fun canScrollHorizontally(): Boolean =
if (!canScrollHorizontally) false
else super.canScrollHorizontally()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment