Created
August 16, 2020 05:55
-
-
Save WSAyan/3b6f0c314c9cd82bff822bd103708e8f to your computer and use it in GitHub Desktop.
Custom RecyclerView with disable touch option.
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 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