Android 工作室包含标记 - 无效的布局参考



我想将一个布局文件包含在另一个布局文件中。我做了一个布局view_camera_and_title.xml。我可以在Android Studio的设计窗口中渲染它,一切正常。

但是当我尝试将其包含在另一个布局文件(名为fragment_note.xml)并运行应用程序时,我收到一个带有以下错误的InflateException:android.view.InflateException:您必须指定有效的布局参考。布局 ID @layout/view_camera_and_title 无效

我在堆栈溢出上看到了所有主题,但没有任何效果。我试图清理项目,重新启动Android Studio。我所有的布局文件和id_values都没有大写符号。没有结果。

我的包含标签没有安卓前缀:

<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="=@layout/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>

有人知道这个问题的解决方案吗?谢谢。

你有<include layout="=@layout/view_camera_and_title"/> .我认为应该是<include layout="@layout/view_camera_and_title"/>,"="是不必要的。

您在以下位置有一个杂散的"="字符:

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

最新更新