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

Android 如何在协调器布局中使用工具栏滚动和折叠线性布局,android,android-layout,android-recyclerview,toolbar,android-collapsingtoolbarlayout,Android,Android Layout,Android Recyclerview,Toolbar,Android Collapsingtoolbarlayout,我试图在应用程序中使用协调器布局实现滚动行为 我为活动提供了以下布局结构 <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.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>

当我向上滚动“回收器”视图项目时,工具栏将折叠并向上移动到窗口外,当我向下滚动时,工具栏将返回

当我滚动“回收器”视图时,是否可以使用工具栏折叠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>

您是否尝试过将线性布局的布局高度与父级匹配。并在其中添加了一些内容???是的。。。你到底想在线性布局中放置什么。所以我可以给你一个样本,我破解了它。我不需要折叠工具栏将Linearlayout移动到appbarlayout中即可。谢谢你的努力。