如何碎片影响的活动和QUOT;单一,集中,用户可以做的&QUOT事;原理? [英] How Fragments affect the Activity "single, focused thing that the user can do" principle?

查看:105
本文介绍了如何碎片影响的活动和QUOT;单一,集中,用户可以做的&QUOT事;原理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Android的文档状态:活动是一个单一的,集中的一点是,用户可以做到

然而,随着片段,我们将能够在相同的活性的雷托•梅耶尔建议。他的建议是由内容片断在同一活动中更换选择片段(节在我们的code这就产生了一个两难)。

比方说我的应用程序是一个位更复杂,有许多活动,具有复杂的导航树,并设计了单一,集中的一点是,用户可以做的原则记在心里。

可以说,现在我必须把它适应碎片和大屏幕...这我不希望创建第二个应用程序,也没有两个完全不同的逻辑(一个用于手机等的表)内的一个应用程序。

我应该有一个活动来管理所有的应用程序片段和片段交易?像复古梅耶尔暗示上方。那是按照推荐的路径?与单一,集中的一点是,用户可以做的原则为活动从而打破?

还是我失去了一些东西?我希望;)

顺便说一句,我认为片段看起来不错,但是从我所看到到现在,只有当您创建一个临时的应用程序。由于制作应用程序与手机和平板电脑兼容看起来会有点乏味。希望是错误的:)


戴安娜Hackborn已经回答了( THX的链接MGV):

  

你可以把一个活动的整个应用程序中,你改变片段结构,其状态更改

那么接下来的活动变成了一种容器,在那里你可以插入片段。我喜欢的方式,但是......我的应用程序可有大约30种不同的操作,每一个要求执行(形式和选择列表),约2〜4步的屏幕,所有的人都不同,也有导航限制。它正常工作与活动的每一个处理一个画面/步的行为。

所以后来移植到片段,我应该移动的每个画面的逻辑片段和利用活动的容器为每个操作。因此,离开活动为那些管理片段之间的导航每个操作,对吧?看起来将是一个痛苦的适应长时间的应用程序。 :(

当前活动的定义应该改了一下BTW。 :)

解决方案
  

我应该有一个活动来管理所有的应用程序片段和片段交易?

这是不可能的,在抽象的回答。然而,大多数的应用将具有多种活性,即使是在一个片段为基础的世界。一些,就可以容纳较小的屏幕尺寸,在那里将趋向于每个活动一个片段。其中一些将需要由框架(例如,从 preferenceActivity 继承)。和,部分的,就可以由GUI设计

  

因此​​,与单一,集中的一点是,用户可以做的原则为活动打破?

文档的那部分写于2008年,也许更早。有碎片存在那时,我想象中的文档会指出一个片段是一个单一的,有重点的东西,用户可以做,以活动作为业务流程层,确定哪些片段是可见在什么情况下。

的文件将不会在所有的地方被更新以反映片段,即使是这样,这将需要一些时间。对于2011年的平衡,至少,你将需要执行自己的2008年时代的指令翻译将其转换为2011时代的片段为基础的用户界面。

  

可以说,现在我必须把它适应碎片和大屏幕...这我不希望创建第二个应用程序,也没有两个完全不同的逻辑(一个用于手机等的表)内的一个应用程序。

我不知道你认为完全不同的逻辑是。在一个片段为基础的应用程序,大部分的业务逻辑将在片段本身。该活动,再次,作为一个业务流程层,确定哪些片段应该是可见的,协调事件处理。后者将得到一点比以前要更复杂,因为有时点击一个列表中的项目将带来一个新的片段,有时在列表中单击某个项目将开始一个新的活动,根据屏幕尺寸。

  

还是我失去了一些东西?

说实话,你缺少足够的具体性,以你的问题,使之合理的交代。

As Android documentation states: "An activity is a single, focused thing that the user can do."

However with Fragments we will be able to do many "things" within the same Activity as Reto Meier suggest. His suggestion is to replace a selection fragment by a content fragment within the same Activity (section "Within our code this produces a dilemma").

Lets say my application is a "bit" more complex, with many activities, with a complex navigation tree and designed with the "single, focused thing that the user can do" principle in mind.

Lets say now I have to adapt it to Fragments and large screens... and that I don't want to create a second application, neither have two completely different logics (one for phones other for tables) inside one application.

Should I have one Activity to manage all the application fragments and fragment transactions? Like Retro Meier suggest above. Is that the recommended path to follow? Thus breaking with the "single, focused thing that the user can do" principle for Activities?

Or am I missing something? I hope ;)

BTW, I think Fragments looks great, but from what I have seen till now, only if you are creating an application from the scratch. Because making applications to be compatible with phone and tablet looks like going to be a bit tedious. Hope to be wrong :)


Dianne Hackborn already has answered (thx for the link mgv):

you could put your entire application in one activity in which you change the fragment structure as its state changes

So then Activity becomes a sort of container where you will be able to plug Fragments. I like the approach, but... in my app there are about 30 different operations available, each one requires about 2 to 4 screens steps to be performed(forms and selection lists), all of them differ and there are also navigation restrictions. It works fine with Activities each one handling one screen/step behaviour.

So then to port to Fragments I should move each screen logic to Fragments and use Activities as containers for each operation. Thus leaving Activities as the ones managing the navigation between Fragments for every operation, right? Looks like going to be a pain to adapt long applications. :(

Current Activity definition should change a bit btw. :)

解决方案

Should I have one Activity to manage all the application fragments and fragment transactions?

That is impossible to answer in the abstract. However, most applications will have multiple activities, even in a fragment-based world. Some of that will be to accommodate smaller screen sizes, where it will tend to be one fragment per activity. Some of that will be required by the framework (e.g., inheriting from PreferenceActivity). And, some of that will be by GUI design.

Thus breaking with the "single, focused thing that the user can do" principle for Activities?

That portion of the documentation was written in 2008, perhaps earlier. Had fragments existed back then, I imagine the documentation would state that a fragment is a "single, focused thing that the user can do", with activities serving as an orchestration layer, determining what fragments are visible in what circumstances.

The documentation will not in all places be updated to reflect fragments, and even if it does, it will take some time. For the balance of 2011, at minimum, you will need to perform your own translations of 2008-era instructions to convert them to 2011-era fragment-based UIs.

Lets say now I have to adapt it to Fragments and large screens... and that I don't want to create a second application, neither have two completely different logics (one for phones other for tables) inside one application.

I have no idea what you consider "completely different logics" to be. In a fragment-based app, most of your business logic will be in the fragments themselves. The activities, again, serve as an orchestration layer, determining what fragments should be visible and coordinating event handling. The latter will get a bit more complicated than it used to be, since sometimes clicking on an item in a list will bring up a new fragment and sometimes clicking on an item in a list will start a new activity, depending on screen size.

Or am I missing something?

To be honest, you are missing enough concreteness to your question to make it reasonably answerable.

这篇关于如何碎片影响的活动和QUOT;单一,集中,用户可以做的&QUOT事;原理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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