Reputation: 2832
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
Upvotes: 2
Views: 158
Reputation: 583
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 Activity
s while maintaining the Navigation Drawer, you will have to use Fragment
s.
Upvotes: 2
Reputation: 35264
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
Upvotes: 1