我有如下一個佈局文件:無法找到包括佈局佈局Android應用
<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>
並呈現如下:
所包含的佈局, tool_bar_activity和create_profile_gallery分別如下:
<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>
和
<HorizontalScrollView 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">
<LinearLayout
android:id="@+id/categories_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
.
.
.
</LinearLayout>
</HorizontalScrollView>
我看到的問題是,findViewById返回null categories_layout但不爲空的工具欄,儘管兩者都包含在各自的(含)的佈局:
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);
爲什麼應該找到一個佈局而不是另一個佈局?
這就是我想,也是。 – FractalBob