gpt4 book ai didi

android - fragment 化还是不 fragment 化?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:56:38 24 4
gpt4 key购买 nike

随着我开始越来越好地采用 Fragments,而且随着 Fragments 功能的增加(Fragments in Fragments、MapFragments),我开始达到需要定义何时应该创建新 View /操作的地步作为 fragment 还是作为 Activity ?

Activity 定义为:

An activity is a single, focused thing that the user can do.

但是 Fragments 有点像文档中描述的那样采用了该定义:

For example, a news application can use one fragment to show a list of articles on the left and another fragment to display an article on the right—both fragments appear in one activity

这是用户可以在具有两个 Fragment 的一个 Activity 中做的两件事。

所以我需要一些输入/帮助来确定什么是决定我应该将新操作/ View 作为 fragment 还是作为 Activity 的最佳方法?

最佳答案

答案取决于您和您的开发实践(或您公司的开发实践)。但是,我的观点是:至少,如果您认为正在开发的功能可以在多个 Activity 中使用,或者如果它可以在一个 Activity 中与另一个 View 一起使用(如在平板电脑上),那么您应该将其制作出来 fragment 。

我们最近采用了在所有情况下都创建 fragment 的理念。我们的 Activity 现在只是顶级协调员,基本上是将事物聚集在一起的粘合剂。这形成了一致且灵活的架构。这对我们很重要,因为我们有许多工程师在几个地方从事代码工作。

关于android - fragment 化还是不 fragment 化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13865300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com