0

I have a collapsing toolbar with tab layout and view pager, I am trying since so long and found to see that my collapsing toolbar is always collapsible whether I have a scrollable data or not. Why is this happening

    <android.support.design.widget.AppBarLayout
            android:id="@+id/appBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="2dp"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Light">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways">

 <FrameLayout
                android:layout_width="match_parent"
                android:visibility="gone"
                android:layout_height="250dp">

//Frame layout for some nested layouts in between

</FrameLayout>

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

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

Am I doing anything wrong. I wanted it to be scrollable only when the view pager pages have scrollable content with it.

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143

1 Answers1

-1

You should add a recyclerview or nested scrollview below the app bar and it must have the following attr

app:layout_behavior="@string/appbar_scrolling_view_behavior"

so now when you scroll, the toolbar will collapse

 <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
M.Ali
  • 8,815
  • 5
  • 24
  • 42
  • check this: https://stackoverflow.com/questions/32557729/how-to-disable-collapsingtoolbars-collapse-when-scroll-has-not-content – M.Ali Jul 09 '18 at 17:26