0

它不想膨脹我的CoordinatorLayout。 Logcat抱怨:獲得CoordinatorLayout使用下面的標題和RecyclerView

java.lang.RuntimeException: Unable to start activity ComponentInfo{....}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class CoordinatorLayout 

我已經搜索溢出並在build.gradle中添加了設計庫依賴項,但它仍然抱怨。是什麼讓它做到這一點,我該如何解決它?

<?xml version="1.0" encoding="utf-8"?> 
<CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 
    <include 
     android:id="@+id/primary_info" 
     layout="@layout/primary_detail_info" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
    <TextView 
     android:id="@+id/tv_title" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:layout_marginStart="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginTop="0dp" 
     android:background="@color/colorPrimaryDark" 
     android:gravity="center_vertical" 
     android:paddingLeft="16dp" 
     android:paddingStart="16dp" 

     android:textColor="@android:color/white" 
     android:textSize="30sp" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:text="Test text" 
     tools:text="Chappie" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview_movie_details" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" 
     android:paddingBottom="8dp"/>  
</CoordinatorLayout> 

的build.gradle:

dataBinding.enabled = true 
} 

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'com.android.support:appcompat-v7:26.0.0' 
    compile 'com.android.support:recyclerview-v7:26.0.0' 
    compile 'com.firebase:firebase-jobdispatcher:0.5.0' 

    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.0' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.0' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
} 
+0

使用並且不要忘記添加gradle依賴關係以及 – nomag

+0

謝謝你nomag,只是試過,仍然拋出錯誤,現在說:android.view.InflateException:二進制XML文件行#0:二進制XML文件行#0:錯誤充氣類android.support.design.widget.CoordinatorLayout –

回答

0

添加到的build.gradle implementation 'com.android.support.constraint:constraint-layout:1.0.2'implementation 'com.android.support:design:26.1.0'和同步的項目

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 
    <include 
     android:id="@+id/primary_info" 
     layout="@layout/primary_detail_info" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
    <TextView 
     android:id="@+id/tv_title" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:layout_marginStart="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginTop="0dp" 
     android:background="@color/colorPrimaryDark" 
     android:gravity="center_vertical" 
     android:paddingLeft="16dp" 
     android:paddingStart="16dp" 

     android:textColor="@android:color/white" 
     android:textSize="30sp" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:text="Test text" 
     tools:text="Chappie" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview_movie_details" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" 
     android:paddingBottom="8dp"/> 
</android.support.design.widget.CoordinatorLayout> 
+0

Got在那裏勞拉,它仍然在拋出錯誤,謝謝你的關注。 –

+0

您可以發佈您在build.gradle文件中的代碼嗎? Thx – Laura

+0

做到了,謝謝你的支持。我非常希望能夠實現這項工作,而不是切換適配器,因爲標題和recyclerview的數據來自兩個不同的來源,一個數據庫和一個網絡請求,因此切換回收站查看器適配器將會是複雜的。 –

相關問題