如何选择活动或片段,如果这两种情况都是可能的? [英] How to choose Activity or Fragment if both scenarios are possible?

查看:109
本文介绍了如何选择活动或片段,如果这两种情况都是可能的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个Android应用程序,类似于一个应用市场,我有一个主页视图和其他两个视图包含列表。所有这三个名单将进入产品列表,但使用不同的参数。而且还有另外一个视图显示了产品的详细信息视图。

In an Android application, similar to an application market, I have a Home view and two other views contain lists. All these three lists will go to a list of products but with different arguments. And there is another view shows the product details view.

在这种情况下,我应该使用片段,当我应该使用活动?以及如何确定?知道我搜索文本框,在其中应该出现在整个系统中的工具栏。

In such a scenario, when should I use Fragments and when should I use Activities? And how to determine? knowing that I search textbox in a tool bar which supposed to appear in the whole system.

我可以有选择现在在所有应用中的一个活动包含搜索工具箱。这一活动将有助于片段之间的导航。另一种选择是,设置所述第一3次中的活性和产品的另一个活动列表中,并将产物细节在一个分隔的一个

The options I may have now is one activity in all the application contains the search toolbox. This activity will help in the navigation between fragments. The other option is to set the first 3 views in an activity, and the list of product in another activity, and the product details in a separated one.

推荐答案

而之所以片段最初创建是为了允许在更大的屏幕设备的模块化布局选项。典型的例子是双窗格的布局,能够适应基于屏幕尺寸。

The reason that fragments were originally created was to allow for modular layout options on larger screen devices. The classic example is the dual pane layout that adapts based on your screen size.

所以,各种各样的问题,你可能会问自己,以确定是否片段是一个很好的选择。分别是:

So the kinds of questions you might ask yourself to determine whether fragments are a good choice for you are:

  1. 请我希望我的应用程序,根据屏幕尺寸来适应它的外观?
  2. 我可以去一个更大的屏幕设备的优势,以显示2,3,4片段在同一屏幕上?
  3. 难道我复制所有我的业务相同的UI元素?

如果是的,碎片你在找什么。如果没有,你也许可以使用的活动。

If yes, fragments are what you are looking for. If no you can probably use activities.

片段是肯定的未来。在您的例子,它包含所有的碎片可能包含搜索栏,并可以处理安装新的碎片,充当中间人的片段之间调度数据的基础活动。

Fragments are certainly the future. In your example your base activity that contains all of your fragments could contain the search bar and could handle attaching new fragments and acting as the middle-man for dispatching data between fragments.

这篇关于如何选择活动或片段,如果这两种情况都是可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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