Reputation: 3515
I am trying to add a relative layout inside of a Coordinator Layout but continuously getting the error No drawer view found with gravity LEFT can some one help me to fix this issue
<?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="end"
android:gravity="left">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/cover"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
app:headerLayout="@layout/main_navigation_header"
app:menu="@menu/sidebar_menu" />
</android.support.v4.widget.DrawerLayout>
Error Stack
05-04 19:00:35.073 14889-14889/sathyabaman.com.coolwallpapers E/AndroidRuntime: FATAL EXCEPTION: main
Process: sathyabaman.com.coolwallpapers, PID: 14889
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1651)
at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1637)
at android.support.v7.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:294)
at android.support.v7.app.ActionBarDrawerToggle$1.onClick(ActionBarDrawerToggle.java:203)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
can some one help me to fix this issue. tnx
Upvotes: 0
Views: 828
Reputation: 7761
android:gravity="left"
is not a valid attribute for DrawerLayout
.
You need to change tools:openDrawer="end"
to tools:openDrawer="start"
for your DrawerLayout
and android:layout_gravity="end"
to android:layout_gravity="start"
for your NavigationView
.
The above solution works if you are opening the drawer with drawer.openDrawer(Gravity.START);
or drawer.openDrawer(Gravity.LEFT);
.
If you want it to open from the right-hand side you may keep your XML as it is and change the way you open the drawer to drawer.openDrawer(Gravity.END);
or drawer.openDrawer(Gravity.RIGHT);
.
Upvotes: 1
Reputation: 23655
I cannot see a gravity=left in your DrawerLayout either.
Add android:gravity="left"
to your DrawerLayout.
Upvotes: 0