首页 > 解决方案 > NestedScrollView 不使用 CoordinatorLayout 滚动

问题描述

尝试在CoordinatorLayout其中滚动内容NestedScrollView不适用于以下片段布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="24dp"
            android:orientation="vertical">

            <!-- Scrollable content -->

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

如何使里面的内容NestedScrollView可滚动?windowSoftInput设置adjustResize为托管活动,主题为Theme.MaterialComponents.Light.NoActionBar。活动也不是全屏的。

标签: androidandroid-coordinatorlayoutandroid-design-libraryandroid-nestedscrollviewandroiddesignsupport

解决方案


必须应用此处提到的解决方法:https ://stackoverflow.com/a/36322516 ,因为没有其他方法对我有用。因此,将此答案标记为已接受,直到将工作解决方案发布为答案


推荐阅读