I am creating app with navigation drawer. There are a lot of examples of creating such apps, but all examples show only how to change one framgent, I mean that activity has only one main fragment with content.
Here is example of such layout from offical docs.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<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>
In this case we are replacing content of content_frame layout with another fragment.
But in my case, I have two fragments on my activity, here is my layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_actionbar">
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/first_fragment"
/>
<View
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="@android:color/darker_gray"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/second_fragment"
>
</FrameLayout>
</LinearLayout>
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment
android:id="@+id/fragment_drawer"
android:name=".NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
So in my case I have two fragment containers for holding differen fragments.
SO I am writing here to get some advices what approach should I follow in this case.
- Create wrapper for two fragments ? And this two layouts will be nested.
- Change two fragments if it is required.
- Open new activity each time user clicks on item in NavDraw menu ?
- Something other ?
Some options in NavDraw menu will open new activity, because it has quite different interface and logic, but there are some screens that can be displayed with the help of replacing fragment.
Also my first_fragment will be present on most pages, so maybe it will be acсeptable way to updating UI in my case.
I want to follow all UI design and building app approaches in order to create responsive app.
Please suggest what is the most acceptable way to implement this.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire