简体   繁体   English

片段切换还是多个活动?

[英]Fragment switching or Multiple activities?

I have a two pane master-detail style application with differing views for the tablet and phone version. 我有一个双窗格主 - 详细信息样式应用程序,具有平板电脑和手机版本的不同视图。 Is it recommended to have a single activity switching fragments in the phone layout or is it better practice to have two activities, one with each fragment? 是否建议在电话布局中使用单个活动切换片段,或者更好的做法是进行两个活动,每个活动一个片段? The android examples have both ways implemented but i am not sure which is the best practice and why? android示例有两种方式实现,但我不确定哪种是最佳实践,为什么?

Afaik, the example of dual pane showed in the official documentation specifies 2 fragments and 2 activities, but this isn't a choice you have to do. Afaik,官方文档中显示的双窗格示例指定了2个片段和2个活动,但这不是您必须做的选择。 Both are required. 两者都是必需的。

  • For phones, activity A shows fragment #1 and activity B shows fragment #2. 对于手机,活动A显示片段#1,活动B显示片段#2。
  • For tablets, activity A shows both fragment #1 and #2, and activity B isn't used. 对于平板电脑,活动A显示片段#1和#2,并且不使用活动B.

I use fragments for this. 我为此使用片段。 On a phone, there's a viewpager which lets the user switch between fragments. 在手机上,有一个viewpager,允许用户在片段之间切换。 On a tablet, fragments are shown at the same time. 在平板电脑上,片段同时显示。 But of course, it all depends on what your app does. 但当然,这完全取决于您的应用程序的功能。

Depending on your app and on the users, you can have a tab bar that lets users switch the viewpager. 根据您的应用和用户,您可以使用标签栏让用户切换viewpager。

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

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