简体   繁体   English

Android:在视图/活动/片段之间滑动切换

[英]Android: on swipe switch between Views / Activities / Fragments

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 eg in the gtalk app. 例如在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 ? 我应该只使用一个Activity实例和几个视图,并在它们之间切换,就像在这个例子中一样
  • 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? FragmentManager是否提供了一种方法来选择正确的Fragment实例以在它们之间进行切换?

What do you think is the best solution, and why? 您认为最好的解决方案是什么?为什么? Any suggestions? 有什么建议么? Thanks for your help! 谢谢你的帮助!

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: 我建议您查看以下Android Dev博客文章,了解如何在Android兼容包中使用ViewPager来实现您正在寻找的滑动功能:

http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html http://android-developers.blogspot.com/2011/08/horizo​​ntal-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. 建议的方法最有可能使用片段作为聊天记录和文本输入字段,因为这将为您提供跨设备的最大灵活性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM