Swipe to switch tab selection

陌路散爱 提交于 2019-11-29 02:33:50

It's certainly possible; you'll need to write a custom layout and override onTouchEvent and onInterceptTouchEvent to decide whether to dispatch gestures through to the children . See HorizontalPager's source for details on how you could go about doing that. You actually may just want to use HorizontalPager straight up (there's a demo on simulating tabs with it), as I think the scrolling content makes it much clearer that you can swipe between tabs.

You can use a gesture detector. As far as I know it listens to gestures "globally". To restrict it to the tab you could check whether the gesture has occurred inside the boundaries of the tab.

GestureDetector

Detects various gestures and events using the supplied MotionEvents. The GestureDetector.OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvents reported via touch (don't use for trackball events). To use this class:

  • Create an instance of the GestureDetector for your View In the nTouchEvent(MotionEvent) method ensure you call
  • onTouchEvent(MotionEvent). The methods defined in your callback will be executed when the events occur

Source: http://developer.android.com/reference/android/view/GestureDetector.html

Swipe Gesture

This page shows how to recognize a swipe-gesture using the GestureDetector: http://smartandroidians.blogspot.com/2010/04/swipe-action-and-viewflipper-in-android.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!