0

This is my Layout xml code

I already have the callback of listview scroll listener but if am doing like

  collapsingToolbarLayout.setVisibility(View.GONE);

its simple hiding the toolbar in place of scrolling effect but i want scrolling effect pls help.

<android.support.design.widget.AppBarLayout
    android:id="@+id/id_toolbar_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:visibility="gone"
        app:layout_collapseMode="pin"
        app:layout_scrollFlags="scroll|exitUntilCollapsed" />
</android.support.design.widget.AppBarLayout>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/id_toolbar_container">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/id_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp">

        //This is the toolbar which i want to hide on scroll of listview
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="enterAlwaysCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white">

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="wrap_content"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginTop="5dp"
                    app:tabMinWidth="75dp"
                    app:tabIndicatorColor="@color/deep_blue"
                    app:tabSelectedTextColor="@color/background"
                    app:tabTextAppearance="@style/MyTabLayoutTextAppearance"
                    app:tabTextColor="@color/myGrey" />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

Rahul
  • 1,380
  • 1
  • 10
  • 24

1 Answers1

5

Scroll behaviors rely on Views that support nested scrolling, which is needed to propagate scroll events up the View tree.

In api-21 the setNestedScrollingEnabled() method was added. In order to get the collapsing Toolbar to work on api-21 and up, call it on the ListView:

myListView.setNestedScrollingEnabled(true);

In order to get it to work on lower api levels, you will need to convert your ListView to a RecyclerView which supports nested scrolling down to api-7 since it's from the v7 support library.

For a full example using a RecyclerView, see here.

Community
  • 1
  • 1
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137