Swipe to select tabs

I have an application that is a Tab activity with various tabs that load an Activity. I would like to add a swipe to switch between tabs, both with the tab control itself and with each action loaded on the tab. Is something like this possible? I’m not sure what “depth” this gesture is for when you make gestures in an Activity located in a tab control, or if internal actions will need to transfer data to the Tab Host.

+5
source share
2 answers

Of course available; you will need to write your own layout and override onTouchEvent and onInterceptTouchEvent to decide whether to send gestures to children. For more information, see the HorizontalPager source for information on how you could do this. In fact, you may just want to use the HorizontalPager straight up (there is a demo of tabs with it there), since I think the scrollable content makes it more understandable so you can scroll between the tabs.

+3
source

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

Gesturedetector

MotionEvents. GestureDetector.OnGestureListener , . MotionEvents ( ). :

  • GestureDetector . nTouchEvent (MotionEvent) ,
  • onTouchEvent (MotionEvent). , , , .

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

, GestureDetector: http://smartandroidians.blogspot.com/2010/04/swipe-action-and-viewflipper-in-android.html

+2

All Articles