NavigationDrawer with Activities

依然范特西╮ 提交于 2019-12-11 02:37:12

问题


Currently in my application i have a navigation drawer. When i began working on it i discovered that many people used fragments instead of activities, however, i needed to work with activities as i realised you weren't able to put fragments within fragments which i would need later on in development.

However, the issue is that by using activities, when i click on a new page from the navigation drawer there isn't a smooth animation as of course the activity has to load up again.

Is there any solution to this? or should i change the application to work with fragments. I have found that people do work with activities when using navigation drawer however i'm unsure if they have solved this issue or just work with it?

Thanks


回答1:


In your XML, when you create a NavigationDrawer you should specify a FrameLayout (or a ViewGroup I guess) that will essentially be the visible screen when the Drawer is not active. In order to actually use this, you have to use a Fragment approach by using the FragmentManager property of your DrawerActivity to swap out the current Fragment based on the list item selected from the Drawer. (I apologize if you already knew that)

Although it is not considered "best practice" but it is possible to nest fragments, see here OR here although you will need either android 4.2 or support library 11 which shouldn't be an issue.

In short, there is no way to use Activitys while maintaining the Navigation Drawer, you will have to use Fragments.




回答2:


You should definitely work with Fragments. I don’t see why people would use activities at all. I guess the Android Developer Training page describes best how to use the NavigationDrawer with Fragments. (Click)

In terms of your concern with fragments within fragments. Since Android 4.2 nested Fragments are possible. The Android Support Library (rev11) added support for nested Fragments later on, so you can basically have nested fragment on every android version.

You can read more about Nested Fragments here: Click



来源:https://stackoverflow.com/questions/25405953/navigationdrawer-with-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!