在Android中嵌套片段不好吗? [英] Is nesting fragments in Android bad?

查看:95
本文介绍了在Android中嵌套片段不好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有作为iOS开发人员的背景,并且目前正在使用Xamarin将应用程序从iOS移植到Android.在这方面,我对Android上的视图层次结构有些疑问.

所附的UML图显示了该应用程序片段之间交互的子集.我希望我的视图控制器类承担有限的责任,通过嵌套片段(相当于iOS上的容器视图控制器)以简洁明了的方式封装功能.

但是,一位Android开发人员告诉我,由于严重的性能下降,嵌套片段是不好的.我不在乎性能会有所下降,但该应用程序当然应该具有响应能力.我们只针对较新的平板电脑和手机.

在Android上应避免片段嵌套吗?以及性能下降(如果有)是什么?(对于此处给出的示例,大约为1毫秒:

更新:该应用的布局如下所示.由于加载了2D/3D模型并可以进行模型操作(全屏显示),并且在应用程序的多个位置使用了ImageEditFlowActivity的流,因此ModelControllerFragment内部的功能相当复杂.CommentListFragment也具有一些非默认行为.将所有这些功能都包含在一个片段中是不希望的.

解决方案

我认为这就是您需要的-http://developer.android.com/training/improving-layouts/optimizing-layout.html)

Thanks!

Update: The layout of the app is shown below. The functionality inside the ModelControllerFragment is rather complicated, since 2D/3D models are loaded and model manipulations can be done (in full screen) and the flow from ImageEditFlowActivity is used from several places in the app. The CommentListFragment also has some non-default behavior. Having all this functionality inside one fragment is not desirable.

解决方案

I think this is what you need - ChildFragmentManager

Main problem in nesting fragments is working with this fragments from parent Fragment. Main issue is find correct fragment in container by id. When project is so huge it is can create a lot of bugs. You can try to imagine when

Fragment1 -> open Fragment2 -> which open Fragment3 -> which have to sent event to Fragment1

This logic is not easy to implement if we want to show the next fragment in the container of current layout.

Related to your class diagram ChildFragmentManager is the best practice to work with nested fragments.

这篇关于在Android中嵌套片段不好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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