嵌套的 ScrollView 在顶部留下一些额外的 space

Nested ScrollView leaves some extra space on top

我在 AppBarLayout 下有一个 NestedScrollView,只有一个 child - LinearLayout。它们都没有填充,顶部也没有边距,但仍然有一些 space 在 NestedScrollView.如何删除它?

我试过在NestedScrollView中设置android:fillViewport="true",但没有结果。

UPD:此 space 与 clipNoPadding 标志交互,但将所有填充设置为 0 无济于事。

<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">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:background="@color/colorAccent"
        android:fillViewport="true"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            android:orientation="vertical">

            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button" />

            // and some more buttons, just to fill the space

        </LinearLayout>

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

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

        // I omit some code, as not-belonging to the question

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

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

how it looks

android:fitsSystemWindows="true" 属性将向应用它的视图添加一些(通常但不总是 24dp)顶部填充。这意味着与透明或半透明状态栏(或导航栏)一起使用,以便您的视图内容不会出现 "under" 状态栏。

在您的屏幕截图中,您似乎没有使用透明状态栏,因此这只会添加您不需要的 24dp 填充。删除它。

另请注意,android:fitsSystemWindows覆盖 使用它的视图上的任何其他填充。因此,即使您手动将内边距设置为 0,您仍将获得 24dp 内边距。