-1

I'm trying to set the DrawerLayout to the right but i get this error:

java.lang.IllegalStateException: Child drawer has absolute gravity RIGHT but this 
DrawerLayout already has a drawer view along that edge

Activity Code:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_categories) {
        //drawerLayout.openDrawer(GravityCompat.END);
        if (drawerLayout.isDrawerOpen(Gravity.RIGHT))
            drawerLayout.closeDrawer(Gravity.RIGHT);
        else
            drawerLayout.openDrawer(Gravity.RIGHT);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

layout

<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/lightGrey"
android:id="@+id/drawer_layout"
tools:openDrawer="end"
tools:context=".MainActivity">

....

<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/navigation_view"
    android:layout_gravity="end"
    app:menu="@menu/categories"/>

I tried multiple solutions from this question but none of them solved the problem. I tried using End instead of Right and GravityCompat instead of Gravity but always get this error.

PHP User
  • 2,350
  • 6
  • 46
  • 87
  • That error means that you've got at least one other child of the `DrawerLayout` that ends up with an absolute layout gravity on the right side. Do you have another child with `layout_gravity` of `right` or `end`? If it's not in the XML, then it's being added in the code, somewhere. – Mike M. May 07 '19 at 13:59
  • there's a recycler view with items set to the right but no child in the same layout set to the right at all – PHP User May 07 '19 at 14:07
  • Please post the complete stack trace. – Mike M. May 07 '19 at 14:08

1 Answers1

0

The DrawerLayout can contain only 2 root layouts so I set the NavigationView and a LinearLayout that contains all other views and it's working now

PHP User
  • 2,350
  • 6
  • 46
  • 87
  • That's not true. `DrawerLayout` can have more than two children, though it often only needs two. This just means that you _did_ have another direct child of the `DrawerLayout` that had a layout gravity that resolved to the right side. – Mike M. May 07 '19 at 14:33