Achieve behaviour same as AppBarLayout for any ViewGroup in CoordinatorLayout
Asked Answered
T

0

9

I'm facing following problem with custom views in CoordinatorLayout: I need to collapse ViewGroup (f.e LinearLayout) when scrolling RecyclerView. ViewGroup acts as header of RecyclerView. When using following code:

<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent">

            <LinearLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways"
                android:orientation="vertical">

                <!-- TextViews, etc. -->

            </LinearLayout>

        </LinearLayout>

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

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

It doesn't work even if I tried to add property app:layout_bevahiour with appropriate value to recycler's header. RecyclerView will occupy all screen and header(LinearLayout) won't show. But when I change LinearLayout to AppBarLayout, everything works as charm but header is styled as action bar.

Is there any way I can achieve behaviour same as AppBarLayout for any ViewGroup (f.e LinearLayout)?

Torquemada answered 7/10, 2015 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.