I'm using a CoordinatorLayout with CollapsingToolbarLayout. I'm trying to put a LinearLayout below AppBarLayout and above the scrolling content, and I want that this LinearLayout stays always fixed on the screen (with AppBarLayout hidden or not), not scrolling with the content.
Is this possible?
So far, I have the following code:
<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>
                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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With