将Navigation Drawer与带有Activities的VS带片段一起使用有什么优势? [英] What are the advantages of using Navigation Drawer with Activities VS with Fragments?

查看:98
本文介绍了将Navigation Drawer与带有Activities的VS带片段一起使用有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中实现一个导航抽屉,但是在是否应该将它与Fragments或Activity一起使用时发生冲突(有关更多详细信息,请参见下图).

I want to implement a Navigation Drawer in my app but I am conflicted on whether I should use it with Fragments or with Activities (see image below for more details).

两者之间是否有真正的优势或劣势?还是只是偏爱问题?

Is there any real advantages or disadvantages between the two or is it just a matter of preference?

只是为了澄清我的问题:

Just to clarify my question:

  1. 如果使用活动"而不是片段";

当我选择导入"将打开一个活动而不是一个片段,并且如果我选择画廊",它将打开一个活动,其中包含图库项目等的内容,以此类推.

When I select "Import" that will open an Activity and not a Fragment and if I select "Gallery" it will open an Activity with contents for gallery item etc. and so on for the other items in the Drawer window.

  1. 如果使用片段而不是活动";

如果我从抽屉"窗口中的任何项目中进行选择,它将为每个选定的项目在片段"中打开其内容,而不是为每个选择启动新的活动.

If I choose from any of the Items in the Drawer window it will open their contents in Fragments for each Item selected instead of starting new Activities for each selction.

推荐答案

记住片段需要一个活动.使用片段时,您总是总是有一个最小值.

Remember Fragments need an Activity. You always have one minimum when using Fragments.

如果您要在大多数情况下谈论像主要元素一样使用,最好使用片段,因为您的UI更具灵活性.

If you are talking about to use like main element in the most cases is best use fragments because you have more flexibility UI.

如果您有3个活动和10个片段,或者有13个活动,性能会更好?考虑一下,在应用程序中导航将是一个巨大的挑战,但这仅是在您的应用程序中使用正确的流程.

The performance would be better if you have 3 activities and 10 Fragments or have 13 Activities? Think about it, the navigation within the App would be the big challenge but it's just about using the right flow in your application.

例如:

带活动而不是片段的抽屉

Drawer With Activities instead of Fragments

如果要使用不带片段的NavigationDrawer,则最好将NavigationDrawer实例保留在单个Activity中,并且当通过从NavigationDrawer中的项目中进行选择来导航应用程序时,每个启动的Activity不应该实现单击NavigationDrawer,但应实现后退按钮以导航回到实现NavigationDrawer的主"/单个活动.

If you were to use NavigationDrawer without Fragments then it would be best to keep the NavigationDrawer instance in a single Activity and when you navigate the app by choosing from the items in the NavigationDrawer then each of those Activities that are started should not implement the NavigationDrawer but instead should implement the back button to Navigate back to the "Main"/single Activity that the NavigationDrawer was implemented in.

注意:如果确实要在多个Activity中实现NavigationDrawer,则必须在每个要显示它的Activity中重新创建NavigationDrawer的新实例.

Note: If you do want to implement the NavigationDrawer in multiple Activities you would have to recreate a new instance of the NavigationDrawer in every Activity that you desire to display it.

我想这与使用片段相比是不利的,而如果使用片段,则不需要很多抽屉实例,只需一个即可.

I suppose this would be a disadvantage vs using Fragments whereas if you used a fragment you wouldn't need many instances of the drawer you would only need one.

带片段的抽屉而不是活动

Drawer With Fragments instead of Activities

如果您使用NavigationDrawer与片段然后抽屉应该在单一的活动来实现,并且被选择的每个抽屉的项目时,则显示其内容在每一他们自己的片段(其被称为管理所述中央活动的内部所有Fragment实例)

If you use the NavigationDrawer with Fragments then the drawer should be implemented in a single Activity and when each drawer item is selected, their contents are displayed in each of their very own Fragments(which is called inside of the central Activity which manages all the Fragment instances)

这篇关于将Navigation Drawer与带有Activities的VS带片段一起使用有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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