Created
October 18, 2019 10:54
-
-
Save EmmanuelGuther/516e5d16573ce8101c86379ad6df5e50 to your computer and use it in GitHub Desktop.
A viewpager with possibilities of being blocked the swipe
This file contains hidden or 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
/** A viewpager with possibilities of being blocked the swipe */ | |
class BViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) { | |
private var enabledSwipe: Boolean = false | |
init { | |
this.enabledSwipe = true | |
} | |
override fun onTouchEvent(event: MotionEvent): Boolean = when { | |
this.enabledSwipe -> super.onTouchEvent(event) | |
else -> false | |
} | |
override fun onInterceptTouchEvent(event: MotionEvent): Boolean = when { | |
this.enabledSwipe -> super.onInterceptTouchEvent(event) | |
else -> false | |
} | |
fun setPagingEnabled(enabled: Boolean) { | |
this.enabledSwipe = enabled | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment