Why do I get an extra 50 pixels of vscrolling on my AppBarLayout with scroll|enterAlways?

前提是你 提交于 2019-12-13 01:00:31

问题


I have the following layout (almost the same as the scrollingActivity generated by Android Studio )

Notice the layout_heights and layout_scrollFlags

<?xml version="1.0" encoding="utf-8"?>
<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="com.man.myapplication.ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:background="@android:color/holo_red_dark"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_green_dark"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/holo_blue_dark"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <include layout="@layout/content_scrolling" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />

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

Problem

After starting the application, the CollapsingToolbarLayout doesn't start from below the statusbar, but from behind it and it still can be scrolled down 50 pixels. (Notice in the gif below in the first view as I start the app)

+ sometimes it snaps below the header (where it should be) when playing with scroll.

Note: this does not appear with the exitUntilCollapsed flag

Question

Is there any way to get rid of that 50 extra pixels scroll and make the Toolbar appear properly under the statusbar?

(currently am debugging the design-support library)


回答1:


Ok I've found a way to get rid of the extra scroll (though not an explanation for why it is happening):

Quickfix

Changing the android:fitsSystemWindows on the AppBarLayout to false gets rid of the extra scroll.

What happens

This setting makes the AppBarLayout begin its layout from the very top of the screen instead from below the statusbar, which somehow gets rid of the weirdscroll.

Note

Though this way your Toolbar won't be hidden nicely below the statusbar.

Result

Footnotes

What is still a mistery, is why doesn't the above behavior take into consideration the statusbar and adds that extra scrollheight. in its original form.



来源:https://stackoverflow.com/questions/35318930/why-do-i-get-an-extra-50-pixels-of-vscrolling-on-my-appbarlayout-with-scrollent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!