美文网首页
AppBarLayout的scrollFlags

AppBarLayout的scrollFlags

作者: Bernardo_Silva | 来源:发表于2019-04-06 09:14 被阅读0次

AppBarLayout的Child View可以在xml布局文件中通过app:layout_scrollFlags设置flag,对应的值为:
scroll,enterAlways,enterAlwaysCollapsed,exitUntilCollapsed,snap。

先贴一下基础代码

<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=".activity.ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        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:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                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"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

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

下面直接看效果:

  • 如果不设置任何flag,AppBarLayout将固定在顶部,无法滚动


    没有设置任何flag.gif
  • 想要AppBarLayout滚动必须设置flag为scroll,另外四个flag需要和scroll一起使用才有效


    设置flag为scroll.gif
  • 设置flag为scroll|enterAlways,则child view优先scroll view滚动并且child view整个滑出屏幕


    设置flag为scroll|enterAlways.gif
  • 设置flag为scroll|enterAlways|enterAlwaysCollasped,向上滑时child view优先scroll view滚动并且child 5. view整个滑出屏幕,向下滑时child view先滚动到最小高度,最小高度通过android:minHeight=""设置,然后scoll view滚动,再是child view滚动


    设置flag为scroll|enterAlways|enterAlwaysCollasped.gif
  • 设置flag为scroll|enterAlwaysCollasped,向上滑时child view优先scroll view滚动并且child 5. view整个滑出屏幕,向下滑时scroll view优先child view滚动


    设置flag为scroll|enterAlwaysCollapsed.gif
  • 设置flag为scroll|exitUntilCollapsed,向上滚动时,child view优先滚动到最小高度,然后会固定在顶部,向下滚动时,scroll view优先child view滚动


    设置flag为scroll|exitUntilCollapsed.gif
  • 设置flag为scroll|snap,当滚动事件结束,如果child view是部分可见的,要么向上全部滚出屏幕,要么向下全部滚进屏幕


    设置flag为scroll|snap.gif

相关文章

网友评论

      本文标题:AppBarLayout的scrollFlags

      本文链接:https://www.haomeiwen.com/subject/nmgliqtx.html