Skip to content

Instantly share code, notes, and snippets.

@wbinarytree
Created December 4, 2018 10:10
Show Gist options
  • Save wbinarytree/7bcc93b59ee8cc117e80e4557dae33e2 to your computer and use it in GitHub Desktop.
Save wbinarytree/7bcc93b59ee8cc117e80e4557dae33e2 to your computer and use it in GitHub Desktop.
ViewPager that can disable scroll.
package fr.airweb.dood.widgets
import android.annotation.SuppressLint
import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
class NoScrollViewPager : ViewPager {
private var isPagingEnabled = true
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
return this.isPagingEnabled && super.onTouchEvent(event)
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return this.isPagingEnabled && super.onInterceptTouchEvent(event)
}
fun setPagingEnabled(b: Boolean) {
this.isPagingEnabled = b
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment