繁体   English   中英

工具栏在CoordinatorLayout中不会在滚动时折叠

[英]Toolbar not collapsing on scroll in CoordinatorLayout

我使用以下布局文件来实现具有折叠工具栏的协调器布局(当用户向下滚动时,它应该折叠,并在向上滚动时重新出现)但是,这个滚动屏幕/折叠功能不起作用,我不知道我知道为什么。 工具栏和标签栏不是反应,而是静态地保持在屏幕顶部。

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <!--                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Alpha" />
            <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Beta" />
            <!-- a bunch of content just to make the view long enough to scroll -->
            <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Upsilon" />

        </LinearLayout>

    </ScrollView>


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorAccent"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />
            <!--                    ^^^^^^^^^^^^^^^^^^ -->

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways" />
            <!--                    ^^^^^^^^^^^^^^^^^^ -->

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_padding"
        android:src="@drawable/ic_add"/>

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

有帮助吗? 谢谢!

据我所知, ScrollView不起作用。 您可以使用NestedScrollViewRecyclerView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM