I am relatively new to Android UI development. So I need help from more experienced developers.
I am building my application with Navigation Drawer , I have encountered many problems.
Firstly, here is a sample code for the navigation box.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> </android.support.v4.widget.DrawerLayout>
This is a simple example from the official site.
The main kind of content (FrameLayout above) should be the first child in DrawerLayout, since the XML order implies a z-order and the box must be on top of the content.
In this example, there are two nested views: FrameLayout , as mentioned earlier, for storing the main content, and ListView for presenting the NavigationDrawer menu.
So here are my questions.
- A real application does not have only one view for all activities. Basically, the activity has many different views and several fragments to make the interface more responsive and provide the user with a better UX. My actions are, of course, different views and fragments (what is the purpose of the same activity? :)). One activity has only one fragment, the other has several fragments, so they are ALL different ... In the previous code example, there is ONLY ONE
FrameLayout container for storing the fragment, only one fragment, which I need to do if my activity has two, three or more fragment? What is the best solution in this case. - As I described, my application has many actions, so my navigation box should (in accordance with the practice of Android UI) for each action, so that the user can go to the top-level elements of the application. In this case, it is better to have one
BaseActivity (here I read the answers to stackoverflow), which will contain all the configuration files for NavigationDrawer . But since DrawerLayout is required in the navigation box in the activity XML layout, BaseActivity must call the setContentView method. And all the actions inherited from BaseActivity must do some tricks to set their own layout, or it makes no sense to redefine this method, because it will break all the logic. What to do in this case? - What is the most efficient way to create a custom list of navigation boxes, for example on Google + or YouTube, without using a complex hierarchy of views that makes the GPU work and can bring the user a bad experience.
For the second problem, I have some ideas on how I can solve this, but I donβt know if this is right and which approach is better.
The first idea is to implement the TemplateMethod template. Create a method in BaseActivity something like setupCustomViewGroup() and redefine it in all assets to inflate the desired group of views from xml and return it from this method, and then use it to inflate the whole view.
Or explicitly add a view to the action, use the merge and include tag.
But again, this can only be useful for whole activities or a single fragment, what if we have more fragments, use nested fragments, I think this is a bad idea.
In addition, my goal is to optimize the hierarchy of views to make it fast and efficient, to ensure smoothness even on older devices.
I will be very very grateful to anyone who can describe or suggest the most effective and correct way to follow in this case, to make the user interface responsive and readable.
Thanks.