滑动切换选项卡选择

发布于 2024-10-31 19:12:45 字数 149 浏览 1 评论 0原文

我有一个应用程序,它是一个选项卡活动,其中包含加载活动的各种选项卡。我想在选项卡控件本身和选项卡中加载的每个活动上添加滑动手势以在选项卡之间切换。这样的事情可能吗?我不确定当您在选项卡控件中托管的活动上做出手势时,会在什么“深度”监听手势,或者内部活动是否必须将数据传递到选项卡主机。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情愿 2024-11-07 19:12:45

这当然是可能的;您需要编写自定义布局并覆盖 onTouchEventonInterceptTouchEvent 决定是否向子级发送手势。有关如何执行此操作的详细信息,请参阅 Horizo​​ntalPager 的源代码。实际上,您可能只想直接使用 Horizo​​ntalPager(有一个关于用它模拟选项卡的演示),因为我认为滚动内容使您可以在选项卡之间滑动更加清晰。

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.

佼人 2024-11-07 19:12:45

您可以使用手势检测器。据我所知,它“全局”监听手势。要将其限制在选项卡中,您可以检查手势是否发生在选项卡的边界内。

手势检测器

检测各种手势和事件
使用提供的 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文