Wow, this is a great tutorial Diana! This is just what I was looking for. Very clearly explained! I have a question- I have fragments that contain buttons, and I want to switch from one fragment to another by clicking on buttons (instead of swiping). So, basically, I want to disable swiping by finger and instead swipe programmatically. Would viewpagers be the best way to do this? I like the sliding animation effect they provide.
The ViewPager is a great choice as you don’t have to implement the sliding animation. You can create a custom ViewPager and disable swiping by overriding onInterceptTouchEvent
and onTouchEvent.
class CustomViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) {
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return false
}
override fun onTouchEvent(event: MotionEvent): Boolean {
return false
}
}
Hi Diana, thanks for the great Tutorial! Have you come across an Android equivalent to iOS ‘Page Control’ widget that would work well with this type of page control? Thanks in advance.