我在 Master Detail Flow Activity 中遇到错误。我使用 android studio GUI 在 android studio 1.5.1 中创建了 Activity 。现在我想在 NestedScrollView
中添加一些 textview
但它会给我错误。我的 XML 代码如下
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="app.burhani.gujaratnow.JobListDetailActivity"
tools:ignore="MergeRootFrame">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/joblist_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/stat_notify_chat"
app:layout_anchor="@+id/joblist_detail_container"
app:layout_anchorGravity="top|end" />
错误是
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.burhani.gujaratnow/app.burhani.gujaratnow.JobListDetailActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
请帮我解决这个错误
最佳答案
You use scrollView according to your error message. And then scrollView should has only one child but your xml says scrollview has one more child.You can move these inside one layout.I hope help you.
关于java - 在 NestedScrollView android 中添加子项时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35113508/