为什么通过scroll | enterAlways在AppBarLayout上获得额外的50个像素的vscrolling? [英] Why do I get an extra 50 pixels of vscrolling on my AppBarLayout with scroll|enterAlways?

查看:89
本文介绍了为什么通过scroll | enterAlways在AppBarLayout上获得额外的50个像素的vscrolling?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下布局(几乎与 Android Studio 生成的scrollingActivity相同)

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

注意layout_height s和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>

问题

启动应用程序后,CollapsingToolbarLayout并非从状态栏下方开始,而是从其后面开始,并且仍可以向下滚动50个像素. (在启动应用程序时,请在以下第一个视图的gif中注意)

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.

注意:这不会与exitUntilCollapsed标志一起出现

Note: this does not appear with the exitUntilCollapsed flag

有什么方法可以消除50个额外的像素滚动并使Toolbar正确显示在状态栏下方?

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)

推荐答案

好吧,我找到了摆脱多余滚动条的方法(尽管没有解释为什么的原因):

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

AppBarLayout上的android:fitsSystemWindows更改为false可以消除多余的滚动.

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

此设置使AppBarLayout从屏幕的顶部而不是状态栏下方开始布局,从而以某种方式摆脱了 weirdscroll .

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.

通过这种方式,您的Toolbar不会很好地隐藏在状态栏下方.

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

仍然令人迷惑的是,为什么以上行为没有考虑状态栏并增加了额外的滚动高度.保持其原始形式.

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.

这篇关于为什么通过scroll | enterAlways在AppBarLayout上获得额外的50个像素的vscrolling?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆