滑动即可切换选项卡选择 [英] Swipe to switch tab selection

查看:155
本文介绍了滑动即可切换选项卡选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它是与装载活动的各种选项卡的标签活动。我想补充轻扫手势在标签之间切换,这两个选项卡控件本身和一个标签加载每一个活动上。是这样的可能吗?我不知道在什么深度的手势听,当你在主持的标签控件的活动作出手势,或者内心活动就必须将数据传递到标签主机。

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.

推荐答案

这当然是可能的;你需要编写一个自定义布局,并覆盖<一href="http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29"相对=nofollow>的onTouchEvent 和<一href="http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent%28android.view.MotionEvent%29"相对=nofollow> onInterceptTouchEvent 以决定是否通过给孩子调度手势。请参见 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.

这篇关于滑动即可切换选项卡选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆