2016-09-23 35 views
2

我在我的應用中使用導航視圖和抽屜佈局。當我試圖執行其拋出的膨脹異常。它支持的MinSdk是14.獲取導航視圖的膨脹異常

另外我用的主題是appcompact沒有操作欄。

主要活動:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/container"> 
    </FrameLayout> 

    <!-- Your normal content view --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:id = "@+id/toolbar_container"> 

     <!-- We use a Toolbar so that our drawer can be displayed 
      in front of the action bar --> 
     <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/main_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 

      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/Contacts" 
      android:layout_gravity="center" 
      android:id="@+id/toolbar_title" 
      android:textSize="20sp" 
      android:textColor="#ffffff" 
      android:textStyle="bold" 
      android:gravity="center" /> 
     </android.support.v7.widget.Toolbar> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#ffffff" 
      android:id="@+id/recycler_view" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentLeft="true" /> 
     <!-- The rest of your content view --> 

    </LinearLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     android:background="?attr/colorPrimary" 
     app:headerLayout="@layout/drawer_header" 
     app:itemTextColor="@color/yourColor" 
     app:itemIconTint="@color/yourColor" 
     app:menu="@menu/nav_menu" > 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <include 
       layout="@layout/drawer_header" 
       android:layout_width="match_parent" 
       android:layout_height="103dp" /> 

      <ExpandableListView 

       android:id="@+id/elvGuideNavigation" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:groupIndicator="@null" 
       /> 

     </LinearLayout> 

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



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

例外:

android.view.InflateException: Binary XML file line #56: Error inflating class android.support.design.widget.NavigationView 
+0

你有沒有檢查這個環節 http://stackoverflow.com/questions/30709419/error-inflating-class-android-support-design-widget-navigationview 我認爲它可以幫助你 –

回答

0

你應該在DrawerLayout內僅使用兩個佈局。主內容的一個佈局,抽屜的另一個佈局(即NavigationView)。目前你有三種佈局。嘗試刪除Framelayout並運行代碼。

+0

還有我震驚的是,同樣的代碼在早期版本中起作用。 @Srijith N – Sid

+0

我刪除了框架佈局,仍然拋出相同的異常。@ Srijith N – Sid

+0

讓我檢查你的xml – Srijith