Android:在视图/活动/片段之间滑动切换
我正在实现一个聊天应用程序。用户可以同时打开多个聊天,我想允许他通过向左或向右滑动来在这些聊天之间切换。就像 gtalk 应用程序中的那样。我不确定实现此目的的最佳方法是什么:
- 我应该为每个聊天使用一个活动吗?如果是,我如何选择正确的活动实例来切换到下一个聊天?
- 我应该只使用一个 Activity 实例和多个视图并在它们之间切换,就像
- 或者我应该使用片段并在它们之间切换? FragmentManager 是否提供了一种方法来选择正确的 Fragment 实例以在它们之间进行切换?
您认为最好的解决方案是什么,为什么?有什么建议吗?感谢您的帮助!
I'm implementing a chat application. The user is able to have multiple chats open simultaneously, and I want to allow him to switch between these chats with swiping left or right. Like e.g. in the gtalk app. I'm not sure what's the best way to implement this:
- Should I use one Activity per chat? If yes, how do I select the correct activity instance for switching to the next chat?
- Should I use only one Activity instance and several views and switch between them like in this example?
- Or should I use Fragments and switch between them? Does the FragmentManager provide a way to pick the right Fragment instance for switching between them?
What do you think is the best solution, and why? Any suggestions? Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您查看以下有关在 Android 兼容性包中使用 ViewPager 来实现您正在寻找的滑动功能的 Android 开发博客文章:
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
推荐的方法最有可能使用 Fragment 进行聊天历史记录和文本输入字段,因为这将为您提供跨设备的最大灵活性。
I would suggest taking a look at the following Android Dev blog post about using ViewPager in the Android Compatibility Package to implement the swipe functionality you're looking for:
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
The recommended approach is most likely to use a Fragment for the chat history and text input field as this will give you the most flexibility across devices.