滑动即可切换选项卡选择选项卡

2023-09-13 23:46:54 作者:Sweethess 甜腻

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

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.

推荐答案

这当然是可能的;你需要编写一个自定义布局,并覆盖的onTouchEvent 和 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.

 
精彩推荐
图片推荐