2016-02-19 49 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