滑动切换选项卡选择
我有一个应用程序,它是一个选项卡活动,其中包含加载活动的各种选项卡。我想在选项卡控件本身和选项卡中加载的每个活动上添加滑动手势以在选项卡之间切换。这样的事情可能吗?我不确定当您在选项卡控件中托管的活动上做出手势时,会在什么“深度”监听手势,或者内部活动是否必须将数据传递到选项卡主机。
I have an application that is a Tab activity with various tabs that load an Activity. I would like to add swipe gesturing to switch between tabs, on both the tab control itself and each activity loaded in a tab. Is something like this possible? I'm not sure at what "depth" the gesture is listened to when you're making gestures on an Activity hosted in the tab control, or if the inner activities would have to pass data to the Tab Host.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这当然是可能的;您需要编写自定义布局并覆盖 onTouchEvent 和 onInterceptTouchEvent 决定是否向子级发送手势。有关如何执行此操作的详细信息,请参阅 HorizontalPager 的源代码。实际上,您可能只想直接使用 HorizontalPager(有一个关于用它模拟选项卡的演示),因为我认为滚动内容使您可以在选项卡之间滑动更加清晰。
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.
您可以使用手势检测器。据我所知,它“全局”监听手势。要将其限制在选项卡中,您可以检查手势是否发生在选项卡的边界内。
GestureDetector 为您提供视图
nTouchEvent(MotionEvent) 方法
确保调用
回调中定义的方法将
事件发生时执行
来源:http://developer.android.com/reference /android/view/GestureDetector.html
滑动手势
此页面展示了如何使用 GestureDetector 识别滑动手势:
http://smartandroidians.blogspot.com/2010 /04/swipe-action-and-viewflipper-in-android.html
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 for your View In the
nTouchEvent(MotionEvent) method
ensure you call
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