如何实现片段之间的水平滚动/滑动? [英] How to implement a horizontal scroll / swipe between Fragments?

查看:13
本文介绍了如何实现片段之间的水平滚动/滑动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中实现导航,例如 Pinterest 或 Trello,即导航 + 水平滚动的三个选项卡.我为此制作了一个自定义标签栏(因为我无法猜测如何使用导航 TAB 模式更改我的操作栏中的标签宽度).所以我有三个按钮可以从一个片段导航到另一个片段.现在我想像这两个例子一样实现水平滚动,也可以在我的片段之间导航.我已经阅读了有关 View Pager 的信息,但我不知道它是否适合我的情况,因为我不仅有视图,还有片段.有没有人有一个例子或如何做到这一点的想法?我可以在不同的活动中应用它吗?谢谢

I would like to achieve a navigation in my app like Pinterest or Trello, that is, kind of three tabs to navigation + horizontal scrolling. I have made a custom tabbar for this (since I couldn't guess how to change tabs width in my actionbar with navigation TAB mode). So I have three buttons to navigate from one fragment to another. Now I would like to implement the horizontal scrolling like these two examples, to also navigate among my fragments. I have read about View Pager but I don't know if it fits to my case, since I don't have only views but fragments. Does anybody have an example or an idea of how to do it? Could I apply it among different activities? Thanks

推荐答案

请看我刚才回答的重复问题:

Please take a look at the duplicate question that I just answered:

如何实现滑动-片段之间的手势?

我想 Android ViewPager 是您正在寻找的:

I suppose the Android ViewPager is what you are looking for:

http://developer.android.com/reference/android/support/v4/view/ViewPager.html

这是一个很好的教程,介绍了如何实现它:

Here is a nice tutorial on how to implement it:

http://developer.android.com/training/动画/screen-slide.html

基本思想是你有多个片段,每个片段代表不同的屏幕. ViewPager 使用户能够在不同的Fragment,显示不同的内容.

The basic idea is that you have multiple Fragments, each representing a different Screen. The ViewPager enables the user to swipe between the different Fragments and display different content.

这篇关于如何实现片段之间的水平滚动/滑动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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