How insert a LinearLayout between AppBarLayout and the scrolling content, when using CollapsingToolbarLayout

断了今生、忘了曾经 提交于 2019-12-05 18:48:58

So far I got this by following:

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

Here Linear layout will scroll but it will always be visible to the user.

I think you can achieve that with this

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

and then include

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

No need to set any scroll flag to the LinearLayout so the CoordinatorLayout will only hide the CollapsingToolbarLayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!