嵌套的ScrollView内容在CoordinatorLayout中无法显示

6
我有一些放在 NestedScrollView 内的内容没有显示出来。唯一显示的是 AppBarLayout 的内容。然而,当我用一个包含 RecyclerView 的片段替换 NestedScrollView 时,它按预期显示。我似乎无法弄清楚我做错了什么。
编辑:我刚刚测试了一下,如果我完全删除 AppBarLayout 并且还删除 NestedScrollView 上的 app:layout_behavior="@string/appbar_scrolling_view_behavior" 属性,则 Android Studio 中的预览窗格会显示我的滚动内容。
<android.support.design.widget.CoordinatorLayout
         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="match_parent"
         android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <!-- Extended toolbar -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"/>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="72dp">

                <EditText
                    android:id="@+id/name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapSentences|textMultiLine"
                    android:hint="Name"/>

            </android.support.design.widget.TextInputLayout>

        </LinearLayout>

    </android.support.design.widget.CollapsingToolbarLayout>

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="visible">

        <!-- Scrolling content here -->

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

尝试从AppBarLayoutCoordinatorLayout中删除android:fitsSystemWindows属性。 - Abhishek V
你是否已经向NestedScrollView添加了内容?如果没有,它将无法显示任何内容 -> 你将看不到任何东西 :) - romtsn
@AbhishekV 那个不起作用。 - user5055032
@Sanvywell,你也从CollapsingToolbarLayout中移除了它吗? - Abhishek V
2个回答

24

尝试将以下行添加到您的NestedScrollView中:

android:fillViewport="true"

同时完成以上两个操作对我很有效。但是我添加第二个片段到最终的线性布局时遇到了问题。 - filthy_wizard
2
请解释一下这个程序的目的,同时也帮助未来的用户。它救了我,请解释一下。 - Ranjithkumar

-4

我在23.1.0版本仍然遇到这个问题。 - frankelot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接