简体   繁体   English

如何在协调器布局中使用工具栏滚动和折叠LinearLayout

[英]How to scroll and collapse a LinearLayout with Toolbar in Coordinator Layout

I'm trying to accomplish a scrolling behavior with coordinator layout in my application. 我正在尝试使用我的应用程序中的协调器布局来完成滚动行为。

I've the following layout structure for the activity. 我有以下活动的布局结构。

<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"
     android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.Dark.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.Dark.PopupOverlay"/>
    </android.support.design.widget.AppBarLayout>

    <!-- The layout to be collapse with toolbar -->
    <LinearLayout
        android:id="@+id/ll_collapse_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

When I scroll up the recycler view items the toolbar collapses and goes up out of the window and when I scroll down I get the toolbar back. 当我向上滚动回收器视图项时,工具栏会折叠并向上移出窗口,当我向下滚动时,我会回到工具栏。

Is it possible to collapse the LinearLayout with toolbar when I scroll the Recycler View? 滚动Recycler View时,是否可以使用工具栏折叠LinearLayout?

<?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="in.test.ProfileActivity">
    <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:contentScrim="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <LinearLayout
                android:id="@+id/ll_collapse_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
         app:layout_collapseMode="parallax"
                android:orientation="horizontal"></LinearLayout>
            <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>
    <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

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

相关问题 使用抽屉布局,协调器布局和片段在滚动时工具栏折叠 - Toolbar collapse on scroll with Drawer Layout, Coordinator Layout, and Fragments 如何在LinearLayout中包装协调器布局? - How to wrap Coordinator Layout in a LinearLayout? 协调器布局 - 工具栏动画,工具栏不会崩溃 - Coordinator Layout - Toolbar animation, Toolbar doesn't collapse 如何在协调器布局中的屏幕底部附加一个 LinearLayout? - How to affix a LinearLayout at the bottom of a screen in coordinator layout? 协调器布局不适用于Linearlayout - Coordinator layout is not working with Linearlayout 当使用协调器布局滚动我的recyclerview时,如何提供自动隐藏/显示工具栏? - How can I provide auto-hide/show toolbar, when scroll my recyclerview with coordinator layout? 如何在协调器布局中添加工具栏标题?-Android - how to add toolbar title in coordinator layout?- android 如何在协调器布局中将FrameView放在工具栏上 - How to place FrameView over Toolbar in Coordinator Layout 如何使用协调器布局在toolbar下设置drawerlayout - How to set drawerlayout below toolbar with coordinator layout 工具栏未隐藏在协调器布局中 - Toolbar not hiding with Coordinator Layout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM