Reputation: 399
The Issue: I've created Activity that contains Drawer and FrameLayout that will be inflated by fragments.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/main_fragment_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- The navigation drawer -->
<RelativeLayout
android:layout_width="200dp"
android:layout_height="match_parent"
android:id="@id/drawerPanel"
android:layout_gravity="start"
android:background="@color/backgroundColor">
<-- CONTENT->>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
After changing/inflating the fragment into FrameLayout main_fragment_panel the drawer should open (everything in logs looks fine) but looks like the fragment overflows everything from activity. How can I change the "level" or "priority" of layout?
UPDATE: I've updated code above - its displaying properly now but didn't handle any events from <-- CONTENT --> (there are some buttons there with listeners)
Upvotes: 0
Views: 42
Reputation: 6396
You should use DrawerLayout as parent layout. Here is the revised code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
android:background="@color/background_material_dark"
app:itemTextColor="@color/colorWhite"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Upvotes: 1
Reputation: 23881
your drawer layout should look like this;
<?xml version="1.0" encoding="utf-8"?>
<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">
<!-- The main content view -->
<LinearLayout
android:id="@+id/llContent"
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" />
</LinearLayout>
<!-- The navigation drawer -->
<!-- Menu items--->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@drawable/background_drawer"
app:headerLayout="@layout/nav_header"
app:itemIconTint="@color/colorPrimary"
app:menu="@menu/menu_navigation" />
</android.support.v4.widget.DrawerLayout>
Now for replacing fragments use:
FragmentTransaction.replace(R.id.content_frame, fragment, tag);
Upvotes: 1
Reputation: 22965
Try something like,
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/right_drawer"
android:name="com.fragments.RightFragment"//your left fragment
android:layout_width="@dimen/drawer_width"
android:layout_height="fill_parent"
android:layout_gravity="left" />
</android.support.v4.widget.DrawerLayout>
Upvotes: 1