简体   繁体   English

多片段最佳实践

[英]Multiple Fragments best practice

I've read this and this about using Fragments. 我读过这个有关使用碎片。

There is an example for how to handle multiple Fragments on a tablet and handset with separate Activities for each Fragment (long story short): 有一个例子说明如何在平板电脑和手机上处理多个片段,每个片段都有单独的活动(长话短说):

With each item of ListFragment 'A', a new Activity for displaying Fragment 'B' is started. 对于ListFragment'A'的每个项目,将启动用于显示片段'B'的新活动。

What is the advantage of using separate Activities for each Fragment instead of using Transactions? 为每个片段使用单独的活动而不是使用事务有什么好处?

In case you want to port your app to phone where fragaments might not be used since the screen is too small to show 2 fragments next to each other - using activities lets you port it quite fast - just need to open another screen for each fragment instead of showing fragments simlutaneously 如果您想将应用程序移植到可能无法使用碎片的手机,因为屏幕太小而无法显示彼此相邻的2个碎片 - 使用活动可以让您快速移植 - 只需要为每个碎片打开另一个屏幕同时显示片段

Actually that is what is meant in the "Design Philosophy" section of the first link you gave 实际上,这就是您给出的第一个链接的“设计理念”部分的含义

I see none. 我没有看到。 If my app runs on tablet I put more fragments on the screen as there's room for this and I got just one activity in which I replace fragments when needed. 如果我的应用程序在平板电脑上运行,我会在屏幕上放置更多碎片,因为这里有空间,我只有一个活动,我需要时替换碎片。 When it is launched on the phone I got less fragments I still follow that pattern - I got single activity and replace fragments in it. 当它在手机上启动时,我得到的片段越来越少,我仍然遵循这种模式 - 我获得了单一活动并替换其中的片段。 I see benefits of that approaches vs using many activities like less flickering, have one logic for whole app. 我看到这种方法的好处与使用许多活动(如闪烁较少)相比,整个应用程序都有一个逻辑。

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

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