Created
August 16, 2020 05:54
-
-
Save WSAyan/720c3b3817f58aea36ced243d38e7089 to your computer and use it in GitHub Desktop.
Disable/enable default scrolling behavior of RecyclerView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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