问题
I have the following layout (almost the same as the scrollingActivity generated by Android Studio )
Notice the layout_height
s 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