java - 在 NestedScrollView android 中添加子项时出错

标签 java android android-layout listview android-fragments

我在 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/

相关文章:

java - Android 改造 Base64 @Body

android - 我应该在已安装的应用程序中与我的免安装应用程序一起实现应用程序链接吗?应用链接的正确实现方式是什么?

android - getheight() 和 getmeasuredheight() 的区别

java - 按下后退按钮时如何将布局设置为先前的布局?

java - 将 ArrayList<Custom Object> 保存到本地存储

java - 使用谷歌应用引擎在 datastore-indexs.xml 中自动生成索引

java - 尝试自动连接到自定义身份验证提供程序时,自动连接服务为空

java - ConcurrentHashMap 在 Guava /咖啡因/中计算?缓存

android - 自定义偏好的标准填充

android - 如何在 Android 中设计微调器