2016-08-04 31 views
1

Ich habe ein Problem mit meiner Symbolleiste für eine Aktivität mit 3 Registerkarten. Es funktioniert auf allen anderen Seiten meiner App, stürzt aber aus irgendeinem Grund ab, wenn ich versuche, auf das Menü auf dieser Seite zu klicken. HierSymbolleiste - Keine Schubladenansicht mit Schwerkraft gefunden LINKS

ist der Fehler:

java.lang.IllegalArgumentException: No drawer view found with gravity LEFT 
                       at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1618) 
                       at android.support.v7.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:290) 
                       at android.support.v7.app.ActionBarDrawerToggle.access$100(ActionBarDrawerToggle.java:64) 
                       at android.support.v7.app.ActionBarDrawerToggle$1.onClick(ActionBarDrawerToggle.java:200) 
                       at android.view.View.performClick(View.java:5697) 
                       at android.view.View$PerformClick.run(View.java:22526) 
                       at android.os.Handler.handleCallback(Handler.java:739) 
                       at android.os.Handler.dispatchMessage(Handler.java:95) 
                       at android.os.Looper.loop(Looper.java:158) 
                       at android.app.ActivityThread.main(ActivityThread.java:7229) 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

Hier ist die xml für das Layout:

<android.support.design.widget.CoordinatorLayout 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/main_content" 
              android:layout_width="match_parent" 
              android:layout_height="match_parent" 
              android:fitsSystemWindows="true" 
              > 


<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    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:paddingTop="0dp"> 

    <include android:id="@+id/app_bar" 
      layout="@layout/toolbar" /> 


    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="48dp"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_below="@id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 



     <fragment 
      android:name="com.bestworkouts.sheikoworkout.NavigationDrawerFragment" 
      android:id="@+id/fragment_navigation_drawer" 
      tools:layout="@layout/fragment_navigation_drawer" 
      android:layout_width="280dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout="@layout/fragment_navigation_drawer" /> 




</android.support.design.widget.AppBarLayout> 

</android.support.v4.widget.DrawerLayout> 

Danke, hoffe jemand kann mir helfen!

Antwort

2

Sie können nicht DrawerFragment innerhalb Kind Blick auf DrawerLayout setzen Sie müssen Schublade Layout oder Schublade Fragment als Kind Ansicht Schublade Layout zu bieten haben. Um Ihr Problem zu lösen, legen Sie Fragment einfach außerhalb von AppbarLayout ab. einfach so:

 <android.support.design.widget.CoordinatorLayout 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/main_content" 
               android:layout_width="match_parent" 
               android:layout_height="match_parent" 
               android:fitsSystemWindows="true" 
               > 


    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     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:paddingTop="0dp"> 

     <include android:id="@+id/app_bar" 
       layout="@layout/toolbar" /> 


     <android.support.design.widget.TabLayout 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="48dp"/> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/view_pager" 
      android:layout_below="@id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 







    </android.support.design.widget.AppBarLayout> 

      <fragment 
       android:name="com.bestworkouts.sheikoworkout.NavigationDrawerFragment" 
       android:id="@+id/fragment_navigation_drawer" 
       tools:layout="@layout/fragment_navigation_drawer" 
       android:layout_width="280dp" 
       android:layout_height="match_parent" 
       android:layout_gravity="start" 
       app:layout="@layout/fragment_navigation_drawer" /> 


    </android.support.v4.widget.DrawerLayout> 
</android.support.design.widget.CoordinatorLayout> 
2

Sie vermissen einen engen Tag für CoordinatorLayout haben am Ende: </android.support.design.widget.CoordinatorLayout>

aber feststellen, dass DrawerLayout ein Top-Level-Layout sein sollte.

Aus Dokumentation:

To use a DrawerLayout, position your primary content view as the first child with a width and height of match_parent. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.

Also ich denke, man es nicht (DrawerLayout) innerhalb eines CoordinatorLayout setzen sollte.

Android DrawerLayout - No drawer view found with gravity

0

java.lang.IllegalArgumentException: keine Schublade Ansicht mit der Schwerkraft gefunden LEFT wollte ich die Schublade von der rechten Kante zu öffnen. Kind Layout Breiten/Höhe nicht für mich funktioniert hat, hatte ich eine Linie, die die ganze illegale Argument Ausnahme verursacht wurde, entfernt, um die Linie
tools:openDrawer="Right" und die Ausnahme Argument ging