Skip to content

Instantly share code, notes, and snippets.

@WSAyan
Created August 16, 2020 05:55
Show Gist options
  • Save WSAyan/3b6f0c314c9cd82bff822bd103708e8f to your computer and use it in GitHub Desktop.
Save WSAyan/3b6f0c314c9cd82bff822bd103708e8f to your computer and use it in GitHub Desktop.
Custom RecyclerView with disable touch option.
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.annotation.Nullable
import androidx.recyclerview.widget.RecyclerView
class CustomScrollableRecyclerView : RecyclerView {
private var isVerticalScrollingEnabled = true
fun enableVerticalScrolling(enabled: Boolean) {
isVerticalScrollingEnabled = enabled
}
override fun computeVerticalScrollRange(): Int {
return if (isVerticalScrollingEnabled) super.computeVerticalScrollRange() else 0
}
override fun onInterceptTouchEvent(e: MotionEvent?): Boolean {
return if (isVerticalScrollingEnabled) super.onInterceptTouchEvent(e) else false
}
constructor (context: Context) : super(context)
constructor (context: Context, @Nullable attrs: AttributeSet?) : super(context, attrs)
constructor (
context: Context,
@Nullable attrs: AttributeSet?,
defStyle: Int
) : super(context, attrs, defStyle)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment