2016-02-19 51 views
0

我想將一個佈局文件包含在另一個佈局文件中。我做了一個佈局view_camera_and_title.xml。我可以在Android Studio的設計窗口中渲染它,一切正常。Android Studio包含標籤 - 無效的佈局參考

但是,當我試圖把它列入其他配置文件(它的命名fragment_note.xml)並運行應用程序我得到與以下錯誤InflateException:android.view.InflateException:您必須specifiy有效佈局參考。版面ID @ layout/view_camera_and_title無效

我看到所有的主題在stackoverflow與同樣的錯誤,但沒有爲我工作。我試圖清理項目,重新啓動Android Studio。我所有的佈局文件和id_value都沒有大寫字母。沒有結果。

我包括標籤是沒有Android前綴:

<include layout="@layout/my_layout"/> 

這是我的佈局文件:

view_camera_and_title.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="16dp" 
       android:layout_marginTop="16dp"> 
    <LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginRight="4dp"> 
     <ImageView 
      android:id="@+id/note_photo" 
      android:layout_width="80dp" 
      android:layout_height="80dp" 
      android:scaleType="centerInside" 
      android:background="@android:color/darker_gray" 
      android:cropToPadding="true"/> 
     <ImageButton 
      android:id="@+id/note_camera" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@android:drawable/ic_menu_camera"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight="1"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/note_title_label" 
      style="?android:listSeparatorTextViewStyle"/> 
     <EditText 
      android:id="@+id/note_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="16dp" 
      android:hint="@string/note_title_hint"/> 
    </LinearLayout> 
</LinearLayout> 

fragment_note.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
    <include layout="[email protected]/view_camera_and_title"/> 
    <Button 
     android:id="@+id/note_time" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp"/> 
    <Button 
     android:id="@+id/note_date" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp"/> 
    <CheckBox 
     android:id="@+id/note_solved" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:text="@string/note_solved_label"/> 
    <Button 
     android:id="@+id/note_partner" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:text="@string/note_partner_text"/> 
    <Button 
     android:id="@+id/note_partner_call" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:text="@string/note_no_partner_call_text"/> 
    <Button 
     android:id="@+id/note_sharing" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:text="@string/note_sharing_text"/> 
</LinearLayout> 

不一個大家知道這個問題的解決方案? 謝謝。

回答

0

您有<include layout="[email protected]/view_camera_and_title"/>。我認爲它應該是<include layout="@layout/view_camera_and_title"/>,'='是不必要的。

+0

感謝ü交配。它看起來像我過度勞累:) – rnknown