Android 使用CollasingToolbarLayout时,如何在AppBarLayout和滚动内容之间插入线性布局

Android 使用CollasingToolbarLayout时,如何在AppBarLayout和滚动内容之间插入线性布局,android,android-collapsingtoolbarlayout,android-appbarlayout,Android,Android Collapsingtoolbarlayout,Android Appbarlayout,我正在使用带有折叠工具栏布局的CoordinatorLayout。我试图在AppBarLayout下方和滚动内容上方放置一个LinearLayout,我希望该LinearLayout在屏幕上始终保持固定(AppBarLayout是否隐藏),而不是滚动内容 这可能吗 到目前为止,我有以下代码: <android.support.design.widget.CoordinatorLayout android:layout_above="@+id/linearLayout" to

我正在使用带有折叠工具栏布局的CoordinatorLayout。我试图在AppBarLayout下方和滚动内容上方放置一个LinearLayout,我希望该LinearLayout在屏幕上始终保持固定(AppBarLayout是否隐藏),而不是滚动内容

这可能吗

到目前为止,我有以下代码:

<android.support.design.widget.CoordinatorLayout
    android:layout_above="@+id/linearLayout"
    tools:context="..."
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <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:minHeight="200dp"
        >

        <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">

            <ImageView
                android:id="@+id/imagemView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"/>

            <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"
                >

                <ImageButton
                    android:id="@+id/back_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:src="@drawable/back_button"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="18dp"
                    android:textSize="25sp" />

            </android.support.v7.widget.Toolbar>

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom|left|end"
        android:layout_margin="@dimen/fab_margin"
        app:borderWidth="0dp"
        app:layout_behavior="myBehavior"/>

    <include
        layout="@layout/content_scrolling" />

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

我认为您可以通过此

<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:minHeight="200dp"
    >

    <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">

        <ImageView
            android:id="@+id/imagemView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"/>

        <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"
            >

            <ImageButton
                android:id="@+id/back_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:src="@drawable/back_button"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="18dp"
                android:textSize="25sp" />

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.CollapsingToolbarLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"/>
</android.support.design.widget.AppBarLayout>

然后包括

<include
    layout="@layout/content_scrolling"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


无需将任何滚动标志设置为LinearLayout,因此CoordinatorLayout将只隐藏正在折叠的工具栏布局

,到目前为止,我通过以下方式实现了这一点:

<CoordinatorLayout>
    <AppBarLayout>
        <CollapsingToolbarLayout>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <LinearLayout
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout/>//Layout which will stay between CollapsingToolbarLayout and Recyler or nested scroll view

    <Recycler Or Nested Scroll View/>

</CoordinatorLayout>

//位于折叠工具栏布局和Recyler或嵌套滚动视图之间的布局

此处线性布局将滚动,但用户始终可以看到它。

将其添加到CollasingToolbarLayout或Scrollview中。尝试了这两种方法,但没有按我的要求工作。在折叠工具栏布局中,LinearLayout覆盖了图像的一部分,在Scrollview中,LinearLayout一起滚动,我希望它在屏幕上保持不变。int-collagingToolbarLayout将LinearLayout重力设置为底部,将image marginbottom设置为LinearLayout的高度。几乎成功了。事实上,LinearLayout保留在我想要的地方,但在滚动内容后面。