Skip to content

Instantly share code, notes, and snippets.

@nikhilpanju
Last active December 2, 2019 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhilpanju/8f4e6581afa44f0d8076d007ba0ebb5c to your computer and use it in GitHub Desktop.
Save nikhilpanju/8f4e6581afa44f0d8076d007ba0ebb5c to your computer and use it in GitHub Desktop.
class NoScrollRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: RecyclerView(context, attrs, defStyleAttr) {
override fun scrollBy(x: Int, y: Int) {
val lm = layoutManager as? NoScrollHorizontalLayoutManager
lm?.canScrollHorizontally = true
super.scrollBy(x, y)
lm?.canScrollHorizontally = false
}
}
class NoScrollHorizontalLayoutManager(context: Context)
: LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) {
var canScrollHorizontally = false
override fun canScrollHorizontally(): Boolean = canScrollHorizontally
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment