简体   繁体   English

如何使用片段处理多个活动?

[英]How to handle multiple activities with fragments?

I need to implement an app through fragments.我需要通过片段实现一个应用程序。

Based on my requirements,i have a menu panel one side and other side i need to display different ui screens based on menu selection.根据我的要求,我的一侧有一个菜单面板,另一侧我需要根据菜单选择显示不同的 ui 屏幕。

My Screen contains heavy ui.That why i design each screen separately.我的屏幕包含大量 ui。这就是为什么我分别设计每个屏幕的原因。

How should i display screens based on menu selections through fragments.我应该如何通过片段显示基于菜单选择的屏幕。

If any one know the solution,Please help me如果有人知道解决方案,请帮助我

Thanks in advance.提前致谢。

If you mean the NavigationDrawer you find the official Tutorial on the Android Developers Website如果您指的是 NavigationDrawer,您可以在 Android 开发者网站上找到官方教程

There is also an example to download, which uses the NavigationDrawer to switch Fragments.还有一个例子下载,使用NavigationDrawer切换Fragment。

If you want a fixed, self-designed Menu and just want to swap out Fragments (holded by a FrameLayout) check out this Tutorial如果您想要一个固定的、自行设计的菜单并且只想换出 Fragments(由 FrameLayout 持有),请查看此教程

Android officially doesn't provide more than one sliding menus (navigation drawers). Android 官方并没有提供一个以上的滑动菜单(navigation drawers)。 You can implement SlideMenu or choose one of many such libraries for more than one sliding menus.您可以实现SlideMenu或为多个滑动菜单选择许多此类库之一。

Once the menus are implemented, it's just a simple case of fragments and activities.一旦菜单被实现,它只是片段和活动的一个简单案例。 There is no "direct way".没有“直接方式”。 Read the documentation and understand how they work.阅读文档并了解它们的工作原理。 Here are some good links这里有一些很好的链接

Fragments - Introduction on developer siteFragments - 开发者网站上的介绍

Tutorial on multi-pane development using fragments by Mr. Vogel Vogel 先生使用片段的多窗格开发教程

Basically what you have to do is, create an Activity extending ActionBarActivity (from support library) or FragmentActivity .基本上你要做的是,创建一个 Activity 扩展ActionBarActivity (来自支持库)或FragmentActivity create fragments and replace them in FragmentManager from your main activity.从您的主要活动创建片段并在FragmentManager替换它们。

See this for reference:请参阅此以供参考:

Creating a navigation drawer 创建导航抽屉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM