Android layout 无法在包含的Android应用程序布局中找到布局

Android layout 无法在包含的Android应用程序布局中找到布局,android-layout,include,Android Layout,Include,我有一个布局文件,其内容如下: <ScrollView 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" android:layout_below="@+id/gallery"

我有一个布局文件,其内容如下:

<ScrollView 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"
android:layout_below="@+id/gallery">

<RelativeLayout
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar_activity" >
    </include>

    <include
        android:id="@+id/gallery"
        android:layout_below="@+id/tool_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        layout="@layout/create_profile_gallery" >
    </include>

    .
    .
    .
</RelativeLayout>
   <android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:titleTextAppearance="@style/ToolbarTitle">

        .
        .
        .
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

为什么要找到一个布局而找不到另一个?

类别\u布局不能为空,因为在活动中调用onCreate方法时,父布局中的所有视图都将加载到内存中

在能够访问其子元素之前,我必须对视图进行充气:

                            // First, inflate the view that contains the layout we want to insert into.
                        LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        // Get a pointer to the gallery layout. This is where gallery items will be inserted.
                        categories_layout = (LinearLayout) findViewById(R.id.categories_layout);
                        categories_layout.removeAllViews();
                        for (int i = 0; i < catNameObj.length; i++) {
                            // Get the view for the gallery items. These will be inserted into categories_layout after the all_categories list
                            // has been downloaded from the server, in downloadFile().
                            galleryView = vi.inflate(R.layout.category_list, null);

                            ImageView imgView = (ImageView) galleryView.findViewById(R.id.node);
                          .
                          .
                          .
//首先,展开包含要插入的布局的视图。
LayoutInflater vi=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
//获取指向库布局的指针。这是将插入库项目的位置。
categories_layout=(LinearLayout)findViewById(R.id.categories_layout);
类别\布局。移除所有视图();
对于(int i=0;i

等等。

我也是这么想的。
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Get a pointer to the gallery layout. This is where gallery items will be inserted.
    categories_layout = (LinearLayout) findViewById(R.id.categories_layout);
                            // First, inflate the view that contains the layout we want to insert into.
                        LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        // Get a pointer to the gallery layout. This is where gallery items will be inserted.
                        categories_layout = (LinearLayout) findViewById(R.id.categories_layout);
                        categories_layout.removeAllViews();
                        for (int i = 0; i < catNameObj.length; i++) {
                            // Get the view for the gallery items. These will be inserted into categories_layout after the all_categories list
                            // has been downloaded from the server, in downloadFile().
                            galleryView = vi.inflate(R.layout.category_list, null);

                            ImageView imgView = (ImageView) galleryView.findViewById(R.id.node);
                          .
                          .
                          .